Reply
How to change db context in D-SQL?
Old 04-11-2008, 02:31 PM How to change db context in D-SQL?
Learning Newbie's Avatar
Moderator

Posts: 4,586
Name: John Alexander
Dynamic SQL, generated inside the database. The code below runs, but does nothing.

Use TruCastEngine
GO
Create Procedure dbo.TestProc As Select @@spid GO
GO
Use IO
GO
Exec sp_executesql N'USE TestDatabase'
Exec sp_executesql N'Drop Procedure dbo.TestProc'

What I'm trying to do is make a stored procedure that can drop objects from a database which is passed in as a parameter. I'd like to save it in master so it's available from all databases on the server.

All SQL object deployments at my company need to have at least 3 lines of code before the header. We require an IF EXISTS(SELECT * FROM SYSOBJECTS WHERE NAME = ? AND TYPE = ?) and the rest. Sometimes it needs a join condition, like if we're adding an index, it needs to look at SYSOBJECTS and SYSINDEXES. The next line is to drop the object if it exists, then GO. I'd like to replace these 3 lines with something like EXEC sp_DropIfExists 'procedure', 'name of proc', 'test database' which would save a lot of time.

Pi in the sky?
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Reply     « Reply to How to change db context in D-SQL?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11446 seconds with 13 queries