5 pts.
 SQL Query
I created a SQL query to restore several databases from a remote location to a test environment. I would like to add a check in the script so that it will not run if connected to certain servers so production databases are not accidentally overwritten

Software/Hardware used:
ASKED: July 9, 2008  6:34 PM
UPDATED: July 10, 2008  1:27 AM

Answer Wiki:
You can use the @@SERVERNAME system variable and the RAISERROR function to do this. IF @@SERVERNAME IN ('Prod01', 'Prod02', 'Prod03') RAISERROR ('This is a production system', 16, 1) This will only terminate the current batch. If you have a GO separator after this the next batch will start.
Last Wiki Answer Submitted:  July 10, 2008  1:09 am  by  Denny Cherry   64,505 pts.
All Answer Wiki Contributors:  Denny Cherry   64,505 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.

 64,505 pts.