LocalDB: How do you delete it?
Setup: Entity framework code first to new database.
Scenario: I'm playing around with EF and I add a bunch of elements to my database. I then change the entity model, and while I know that I could do migrations, I just want to start from scratch and basically wipe the database from the earth.
The database used by default was (localdb)\v11.0.
My question is:
Can I go somewhere and just delete a file, or start some kind of manager to delete that database and start from scratch?
Just go in command prompt with admin rights and type:
//list the instancies
sqllocaldb i
//stop selected instance
sqllocaldb p "selected instance"
//delete
sqllocaldb d "selected instance"
//recreate or create new one
sqllocaldb c "new instance"
From Visual Studio => Click View => SQL Server Object Explorer=> Right click the desired database and choose delete and it will be deleted or do whatever you want
If you're using Entity Framework Core, you can enter this in the Package Manager Console:
PM> Drop-Database
It will drop the current database. This command will tell you which one:
PM> Get-DbContext
This is also handy:
PM> Get-Help about_EntityFrameworkCore
Instead of the Package Manager Console, you can also use the dotnet CLI via PowerShell or the command prompt:
PS> dotnet ef database drop
Make sure you install the EF extension first by running this command:
dotnet tool install --global dotnet-ef
I think you want to delete an individual database, not a LocalDB instance. If so, just issue a drop database command:
DROP DATABASE databasename;
You can do this from sqlcmd
, Management Studio, your application code, maybe even Visual Studio...