I was wondering if it was possible to check what server database you are currently connected to, using T-SQL, when executing commands in Query Analyzer. Even though you choose the server and database when connection, sometimes by habit you may connect to the wrong server & DB, and execute an .SQL file. Is it possible to put a line of T-SQL at the beginning that performs this pseudo-code, as a safety feature:
-- While in Query Analyzer with a certain .SQL file open:
If current server <> 'TheCorrectServer' and current DB <> 'TheCorrectDB' then cancel this .SQL file execution.Hi there
In Query analyzer type the following to get server name
select @.@.servername
Unsure how to get database name, you could just always put;
use <databasename>
in your code, that way you would always be on the right database|||SELECT db_name()
returns the currently active database|||Thanks a lot! That will help.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment