SQL 删除和删除数据库有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2452524/
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
What is the difference between drop and delete database?
提问by BreakHead
What is the difference between drop and delete database?
删除和删除数据库有什么区别?
回答by Ravia
Difference between DELETE and DROP commands
Delete:The DELETE command is used to remove rows from a table. A WHERE clause can be used to only remove some rows. If no WHERE condition is specified, all rows will be removed. After performing a DELETE operation you need to COMMIT or ROLLBACK the transaction to make the change permanent or to undo it. Note that this operation will cause all DELETE triggers on the table to fire.
Drop:The DROP command removes a table from the database. All the tables' rows, indexes and privileges will also be removed. No DML triggers will be fired. The operation cannot be rolled back.
删除:DELETE 命令用于从表中删除行。WHERE 子句可用于仅删除某些行。如果未指定 WHERE 条件,则将删除所有行。执行 DELETE 操作后,您需要提交或回滚事务以使更改永久或撤消。请注意,此操作将触发表上的所有 DELETE 触发器。
删除:DROP 命令从数据库中删除一个表。所有表的行、索引和权限也将被删除。不会触发 DML 触发器。该操作无法回滚。
回答by gpmcadam
Simply: a DELETE
command removes matching rows, a DROP
command removes the entire table.
简单地说:一个DELETE
命令删除匹配的行,一个DROP
命令删除整个表。
回答by Rahul Patel
Deleteremoves content of table.Dropremoves content and structure of table.Deletecan be rolled back but Dropcan not be rolled back
删除删除表的内容。Drop删除表的内容和结构。删除可以回滚但删除不能回滚
回答by AgentNaz
I know this is an old post, but I was looking for the answer myself, and since I believe the OP has asked about dropping or deleting the database, rather than tables or content, I thought I'd chip in.
我知道这是一篇旧帖子,但我自己也在寻找答案,因为我相信 OP 已经询问了删除或删除数据库,而不是表格或内容,所以我想我会插手。
Both will delete the database, but both could involve more than one step if you want to completelyremove the database and associated artefacts.
两者都将删除数据库,但如果您想完全删除数据库和相关的人工制品,两者都可能涉及多个步骤。
DELETE
删除
If you are using SQL Server Management Studio, you can delete the database by right clicking on the database and selecting Delete. The resulting dialog offers a couple of checkboxes :
如果您使用的是 SQL Server Management Studio,则可以通过右键单击数据库并选择删除来删除该数据库。结果对话框提供了几个复选框:
- 'Delete backup and restore history information for databases'
- 'Close Existing connections'
- '删除数据库的备份和恢复历史信息'
- '关闭现有连接'
If you don't tick 'Delete backup and restore history..' , those files will remain on the server unless you manually get rid of them. 'Close Existing connections' is a good idea, otherwise you may get an error telling you the database is still in use (even if it's just you, while you're trying to delete it)
如果您不勾选“删除备份和还原历史记录..”,除非您手动删除它们,否则这些文件将保留在服务器上。“关闭现有连接”是个好主意,否则您可能会收到一条错误消息,告诉您数据库仍在使用中(即使只有您在尝试删除它)
DROP
降低
The SQL Command 'DROP' alone will not remove everything. You will still need to also remove the backup history, and set the database to 'single user mode' - or it may complain the database is still in use, as above.
单独的 SQL 命令“DROP”不会删除所有内容。您仍然需要删除备份历史记录,并将数据库设置为“单用户模式” - 否则它可能会抱怨数据库仍在使用中,如上所述。
--Remove backup history
EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'YourDBName'
GO
USE [master]
GO
--close all the open connections to your database
ALTER DATABASE [YourDBName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
USE [master]
GO
--remove the actual database
DROP DATABASE [YourDBName]
GO
回答by AgentNaz
Delete removes content and drop the structure of a database.
删除删除内容并删除数据库的结构。
回答by Saad Qureshi
Suppose you are using MS SQL
Then if you want to delete the whole Table
then you would use:
假设你正在使用 MS SQL 那么如果你想删除整个,Table
那么你可以使用:
DROP TABLE MyTable
删除表 MyTable
This would delete the whole table and its constraints
这将删除整个表及其约束
To delete any specific row you would use:
要删除您将使用的任何特定行:
DELETE FROM MyTable WHERE id=5
从 MyTable 中删除 id=5
This would delete the row with the id = 5 If no conditions are matched it would delete all rows
这将删除 id = 5 的行如果没有匹配条件,它将删除所有行
回答by Harshit Chandani
Drop in a function that physically removes and particular table or a column. The table struction remails same. If you want to see the structure, you can write this desc tablename; and the structure will be same after dropping the table. Delete function permanantly deletes the table or a column, the structure of the table also.
放入一个物理删除特定表或列的函数。表结构相同。如果想看结构,可以写这个desc tablename;删除表后结构将相同。删除功能永久删除表或列,表的结构也是如此。
回答by Ignacio Vazquez-Abrams
DROP
removes the entire table and associated objects from the catalog, requiring you to create all the indexes and constraints from scratch.
DROP
从目录中删除整个表和关联对象,需要您从头开始创建所有索引和约束。