删除所有记录
如何删除SQL Server 2008中的所有记录?
How to delete all the records in SQL Server 2008?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何删除SQL Server 2008中的所有记录?
How to delete all the records in SQL Server 2008?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(10)
删除表中的所有记录而不删除表。
DELETE FROM table_name
请谨慎使用,无法撤消!删除表
DROP TABLE table_name
To delete all records from a table without deleting the table.
DELETE FROM table_name
use with care, there is no undo!To remove a table
DROP TABLE table_name
从桌子上?
如果您没有其他表的外键
或者
您想要所有表,则可以使用此选项
from a table?
You can use this if you have no foreign keys to other tables
or
if you want all tables
使用 DELETE 语句
例如:
Use the DELETE statement
Eg:
我可以看到上面显示的其他答案是正确的,但我会让你的生活变得轻松。
我什至为你创建了一个例子。我添加了一些行并想删除它们。
您必须右键单击该表,如图所示 Script Table a>删除至>新查询编辑器窗口:
然后将打开另一个带有脚本的窗口。删除“where”行,因为要删除所有行。然后单击执行。
要确保您执行此操作,请右键单击表格,然后单击“选择前 1000 行”。然后你可以看到查询是空的。
I can see the that the others answers shown above are right, but I'll make your life easy.
I even created an example for you. I added some rows and want delete them.
You have to right click on the table and as shown in the figure Script Table a> Delete to> New query Editor widows:
Then another window will open with a script. Delete the line of "where", because you want to delete all rows. Then click Execute.
To make sure you did it right right click over the table and click in "Select Top 1000 rows". Then you can see that the query is empty.
如果你想重置你的表,你可以执行
truncate 需要特权,并且如果你的表有依赖项(另一个具有你的表的 FK 的表,
If you want to reset your table, you can do
truncate needs privileges, and you can't use it if your table has dependents (another tables that have FK of your table,
对于一张表
对于所有表
For one table
For all tables
如果要删除数据库中的记录,请删除“结果”窗格中的行。如果要删除所有行,可以使用删除查询。
Delete rows in the Results pane if you want to delete records in the database. If you want to delete all of the rows you can use a Delete query.
这不是一个好的做法。
就像在 Google BigQuery 中一样,它不允许在没有“where”子句的情况下使用删除。
改用
isn't a good practice.
Like in Google BigQuery, it don't let to use delete without "where" clause.
use
instead
当表很大时,如果有建表查询,最好使用
drop table TableName
删除表本身并重新创建;使用delete from
语句而不是逐条删除记录,因为这可能非常耗时。When the table is very large, it's better to delete table itself with
drop table TableName
and recreate it, if one has create table query; rather than deleting records one by one, usingdelete from
statement because that can be time consuming.如果您愿意以合理的权限删除所有记录,则语句为
DELETE FROM YourDatabaseName.SomeTableName;
。但是您可能会在为外键定义的约束中看到错误。因此,您需要在删除记录之前更改约束,否则 MySQL 有一个命令(可能对其他人有效)来忽略约束。请注意,此命令将禁用外键约束检查,因此这对于您在架构中创建的关系可能很危险。
The statement is
DELETE FROM YourDatabaseName.SomeTableName;
if you are willing to remove all the records with reasonable permission. But you may see errors in the constraints that you defined for your Foreign Keys. So that you need to change your constraints before removing the records otherwise there is a command for MySQL (which may work for others) to ignore the constraints.Please be aware that this command will disable your foreign keys constrain check, so this can be dangerous for the relationships you created within your schema.