Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Identifying database for a specific command
Message
 
 
To
22/03/2011 14:49:51
General information
Forum:
Microsoft SQL Server
Category:
Scripting
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01504553
Message ID:
01504555
Views:
51
This message has been marked as the solution to the initial question of the thread.
>If I have the following command:
>
>
>IF EXISTS(SELECT 1 FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'MyTable') AND type = (N'U')) PRINT 'TEST'
>
>
>How can I adjust it to have it bound to another database then the one the script window is defaulting to?
IF EXISTS (select 1 from myDB.sys.Objects WHERE OBJECT_ID = OBJECT_ID(N'MyTable') AND type = (N'U')) PRINT 'TEST'
Alternatively,
IF EXISTS (select 1 from MyDB.INFORMATION_SCHEMA.Tables where TABLE_Name = 'MyTable') PRINT 'TEST'
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform