Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Bex
Aged Yak Warrior
580 Posts |
Posted - 2007-11-20 : 06:49:15
|
HiI want to be able to create a procedure whilst connected to a different database. I can do this when creating tables by fully qualifying the name, but cannot use this method for procedure creations:CREATE DATABASE Test1GOCREATE DATABASE Test2GOUSE Test1GO-- Method 1 - doesn't allow you to do this as CREATE has to be first in batchIF OBJECT_ID('Test2.dbo.Test2Proc') IS NULLCREATE PROCEDURE Test2.dbo.Test2ProcASPRINT 'Hello'GO-- Method 2 - works but not using server nameIF OBJECT_ID('Test2.dbo.Test2Proc') IS NOT NULLDROP PROCEDURE Test2.dbo.Test2ProcGOCREATE PROCEDURE Test2.dbo.Test2ProcASPRINT 'Hello'GOUSE [Master]DROP DATABASE Test1GODROP DATABASE Test2GOIs what I want to do possible? ThanksHearty head pats |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-11-20 : 08:41:02
|
| exec svr.db.dbo.sp_executesql N'CREATE PROCEDURE Test2ProcASPRINT ''Hello'''I usually create a file and execute it in the database using osql.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
Bex
Aged Yak Warrior
580 Posts |
Posted - 2007-11-20 : 09:30:06
|
That works a treat. Thankyou Hearty head pats |
 |
|
|
|
|
|