C# LocalDB:你如何删除它?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15318843/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 16:24:28  来源:igfitidea点击:

LocalDB: How do you delete it?

c#visual-studiosql-server-express

提问by Gabriel G. Roy

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.

场景:我正在使用 EF,并向我的数据库中添加了一堆元素。然后我更改实体模型,虽然我知道我可以进行迁移,但我只想从头开始,基本上从地球上擦除数据库。

The database used by default was (localdb)\v11.0.

默认使用的数据库是 (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?

我可以去某个地方删除一个文件,或者启动某种管理器来删除该数据库并从头开始吗?

回答by Aaron Bertrand

I think you want to delete an individual database, not a LocalDB instance. If so, just issue a drop database command:

我认为您要删除单个数据库,而不是 LocalDB 实例。如果是这样,只需发出 drop database 命令:

DROP DATABASE databasename;

You can do this from sqlcmd, Management Studio, your application code, maybe even Visual Studio...

您可以从sqlcmdManagement Studio、您的应用程序代码,甚至 Visual Studio 执行此操作...

回答by Filip Gjorgjevikj

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"

回答by Mohamed Salah Darwish

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

从 Visual Studio => 单击查看 => SQL Server 对象资源管理器 => 右键单击​​所需的数据库并选择删除,它将被删除或执行您想要的任何操作

回答by Dave Ziffer

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.

LocalDB 是它自己的独立服务器(它的名字暗示它只是其他服务器实例中的一个数据库,但事实并非如此)。在 SQL Server 2014 Express 中,您可以使用服务器名称“(localdb)\MSSQLLocalDB”连接到它,就像连接到任何普通数据库服务器一样。如果您使用 SQL Server Management Studio 进行连接,那么您就可以使用 SSMS 的所有功能。

回答by Moerwald

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

是的你可以。在 VS 2015/2017 中按 Ctrl+Q,输入“对象资源管理器”。“SQL Server 对象资源管理器”应该会打开,您将在其中看到您的本地数据库实例。展开数据库实例,您将看到不同的数据库。选择一个数据库执行右键单击并选择“删除”。

For additional information check this link.

有关其他信息,请查看此链接

Hope that helps.

希望有帮助。

回答by Matt Gregory

If you're using Entity Framework Core, you can enter this in the Package Manager Console:

如果您使用的是 Entity Framework Core,则可以在包管理器控制台中输入:

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

回答by Mike Godin

With Entity Framework Core, this can also be accomplished form the the command line:

使用 Entity Framework Core,这也可以从命令行完成:

dotnet ef database drop --project [path to project]

Or if you have multiple database contexts:

或者,如果您有多个数据库上下文:

dotnet ef database drop --project [path to project] --context [ContextName]

回答by Nick B

Entity Framework 3.1:

实体框架 3.1:

Drop Database

删除数据库

dotnet ef database drop

Do not want to drop database, willing to delete tables in the database

不想删除数据库,愿意删除数据库中的表

dotnet ef database update 0