There are two ways to prevent your SQL code from running on a testing server or production server. You can use the @@SERVERNAME Variable or the DB_NAME function, as shown next below:
@@SERVERNAME
IF @@SERVERNAME = 'ProductionServerName'
BEGIN
PRINT 'Code will NOT execute'
RETURN
END
ELSE
BEGIN
PRINT 'Code will execute'
END
DB_NAME()
IF DB_NAME() = 'ProductionServerName'
BEGIN
PRINT 'Code will NOT execute'
RETURN
END
ELSE
BEGIN
PRINT 'Code will execute'
END
Visit the DevX Tip Bank