Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

A note to the provided script. Expand / Collapse
Posted Wednesday, December 31, 2008 6:19 AM


Group: General Forum Members
Last Login: Thursday, July 30, 2015 12:35 AM
Points: 18, Visits: 62
First when a saw this line, I was glad to see a trick how to work around the limitiation, that the Sqlserver does not allow to change the database context within a stored proc. But playing around with it quickly revealed that this workaround does not work around.

Statements called within an exec('...') clause are executed as a batch separate from the caller's batch, including the database context.


-- start example
Use AdventureWorks;
print db_name();
exec('use master; print db_name();');
print db_name();
-- end example

The output will be:

Post #628001
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse