LocalDB: How do you delete it?

2020-02-17 04:04发布

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?

6条回答
干净又极端
2楼-- · 2020-02-17 04:36

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.

查看更多
狗以群分
3楼-- · 2020-02-17 04:43

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
查看更多
Rolldiameter
4楼-- · 2020-02-17 04:51

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

查看更多
Animai°情兽
5楼-- · 2020-02-17 04:56

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

查看更多
\"骚年 ilove
6楼-- · 2020-02-17 04:59

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.

查看更多
一纸荒年 Trace。
7楼-- · 2020-02-17 05:02

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"
查看更多
登录 后发表回答