Created
July 19, 2017 16:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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