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

Enjoy.

 

Advertisements

About Andrew Butenko

https://www.mcpvirtualbusinesscard.com/VBCServer/a9939be0-be6f-4249-a775-6665eccff2e4/card https://www.microsoftvirtualacademy.com/Profile.aspx?alias=530492
This entry was posted in SQL. Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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