devxlogo

Preventing SQL from Running on a Testing SQL Server

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:

@@SERVERNAMEIF @@SERVERNAME = 'ProductionServerName'BEGINPRINT 'Code will NOT execute'RETURNENDELSEBEGINPRINT 'Code will execute'ENDDB_NAME()IF DB_NAME() = 'ProductionServerName'BEGINPRINT 'Code will NOT execute'RETURNENDELSEBEGINPRINT 'Code will execute'END
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist