dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Jan 22, 2019

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Preventing SQL from Running on a Testing SQL Server

There are two ways to prevent your SQL code from running on a testing 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
Hannes Du Preez
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Thanks for your registration, follow us on our social networks to keep up-to-date