LocalDB: How do you delete it?

2020-02-17 04:54发布

问题:

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?

回答1:

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"


回答2:

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



回答3:

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


回答4:

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...



回答5:

Yes you can. In VS 2015/2017 press Ctrl+Q, type "object explorer". The "SQL Server Object Explorer" should open, where you'll see your local DB instances. Expand the DB instance, and you'll see the different databases. Select one database perform a right click and choose "Delete".

For additional information check this link.

Hope that helps.



回答6:

LocalDB is its own separate server (its name suggests that it is just a database in some other server instance but this is not the case). In SQL Server 2014 Express you connect to it using server name "(localdb)\MSSQLLocalDB", just as you would connect to any ordinary database server. If you connect using SQL Server Management Studio then you have all the power of SSMS available to you.