Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



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

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
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?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to How to change db context in D-SQL?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.09630 seconds with 12 queries