0

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?

Community
  • 1
  • 1

2 Answers2

0

Try the Object Explorer Details pane as follows:

  1. Open Object Explorer Details (View menu)
  2. Click on the Databases node of the Object Explorer
  3. In Object Explorer Details, multi-select the databases you want to delete by depressing the Ctrl or Shift key while selecting them
  4. 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!

enter image description here

@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