Skip to content

Instantly share code, notes, and snippets.

@calderhayes
Created July 19, 2017 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calderhayes/462693f53b42fe21cc8351edb46a9b75 to your computer and use it in GitHub Desktop.
Save calderhayes/462693f53b42fe21cc8351edb46a9b75 to your computer and use it in GitHub Desktop.
To safely drop a development database, incase you are working with a PROD database with a user that has DROP permissions
USE master;
-- MS SQL SERVER
-- To safely drop a development database, incase you are working with a PROD database with a user that has DROP permissions
DECLARE @MyDevServerName NVARCHAR(255) = 'T1DTC075\LOCALDB'
DECLARE @MyDatabase NVARCHAR(255) = 'TestDB'
DECLARE @DropStatement NVARCHAR(500) = 'DROP DATABASE ' + @MyDatabase
IF @@SERVERNAME LIKE (@MyDevServerName + '%')
EXEC sp_executesql @DropStatement
ELSE
PRINT 'You are trying to DROP the database ' + @MyDatabase + ' ON ' + @MyDevServerName + ' you DUMMY';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment