Last active
January 20, 2017 16:28
-
-
Save tillig/81b9527fbd20c8ef7fff13c59f13d239 to your computer and use it in GitHub Desktop.
Kill an Entire LocalDB Instance
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
$LocalDB = "YourInstanceName" | |
& "$($env:ProgramFiles)\Microsoft SQL Server\110\Tools\Binn\sqlcmd.exe" -S "(localdb)\$LocalDB" -d "master" -Q "EXECUTE master.sys.sp_MSforeachdb 'USE [?];declare @name nvarchar(max) = DB_NAME();IF(@name NOT IN (''master'',''model'',''msdb'',''tempdb''))BEGIN USE [master];EXEC (''alter database ['' + @name + ''] set single_user with rollback immediate; DROP DATABASE '' + @name) END'" | |
& sqllocaldb p $LocalDB | |
& sqllocaldb i $LocalDB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment