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
Author
Message
Posted Wednesday, December 31, 2008 6:19 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Sunday, May 11, 2014 3:35 PM
Points: 18, Visits: 56
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.

Example:

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

The output will be:
AdventureWorks
master
AdventureWorks

Post #628001
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse