Do not run this in production!

Some actions are dangerous for a production environment. How to guarantee that action applied in a test environment only?

Here is the example of TSQL script checking if the current database has “_Test” suffix (it could be server name, or variable, the idea is the same).

IF (db_name() NOT LIKE '%[_]Test') 
    RAISERROR ('DO NOT RUN THIS SCRIPT IN PROD!!! Stop processing!!!'
      , 20, 1) WITH LOG
select * from sys.tables

This simple check guarantees that last string (and afterward) would not run. There are 2 compulsory conditions (highlighted):

  • error level must be 20 (not 16)
  • error raised with logging




About Andrew Butenko
This entry was posted in SQL. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s