This is related to a previous question How to delete (localdb) database if the file is gone.
I use SQL Server Management Studio 2012 to edit local databases created within Visual Studio by connecting to (LocalDB)\v11.0 as server. After a while, I would see all the databases that I ever connected to, most of which are gone. I can delete/detach these long-gone databases one by one manually. But would appreciate a way to delete all of them in one shot. ANyone can help?
Asked
Active
Viewed 321 times
0

Community
- 1
- 1

user2002094
- 1
- 3
2 Answers
0
Try the Object Explorer Details pane as follows:
- Open Object Explorer Details (View menu)
- Click on the Databases node of the Object Explorer
- In Object Explorer Details, multi-select the databases you want to delete by depressing the Ctrl or Shift key while selecting them
- Right click and select Delete

David Atkinson
- 5,759
- 2
- 28
- 35
0
I wrote a simple batch file to delete an SQL local db. It uses trusted connection. But you can add credentials with -U Username
-P Password
parameters. Further info check out!
@echo off
set /p DbName=Enter local db name:
echo.
sqlcmd -e -S "(LocalDb)\MSSQLLocalDB" -d "master" -Q "EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'%DbName%'; USE [master]; DROP DATABASE [%DbName%];"
echo Finished!
pause > nul

Alper Ebicoglu
- 8,884
- 1
- 49
- 55