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