删除所有记录

发布于 2024-10-22 18:27:38 字数 33 浏览 6 评论 0原文

如何删除SQL Server 2008中的所有记录?

How to delete all the records in SQL Server 2008?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

°如果伤别离去 2024-10-29 18:27:38

删除表中的所有记录而不删除表。

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

紫竹語嫣☆ 2024-10-29 18:27:38

从桌子上?

如果您没有其他表的外键

truncate table TableName

或者

delete TableName

您想要所有表,则可以使用此选项

sp_msforeachtable 'delete ?'

from a table?

You can use this if you have no foreign keys to other tables

truncate table TableName

or

delete TableName

if you want all tables

sp_msforeachtable 'delete ?'
瑕疵 2024-10-29 18:27:38

使用 DELETE 语句

Delete From <TableName>

例如:

Delete from Student;

Use the DELETE statement

Delete From <TableName>

Eg:

Delete from Student;
小伙你站住 2024-10-29 18:27:38

我可以看到上面显示的其他答案是正确的,但我会让你的生活变得轻松。

我什至为你创建了一个例子。我添加了一些行并想删除它们。

您必须右键单击该表,如图所示 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:

enter image description here

Then another window will open with a script. Delete the line of "where", because you want to delete all rows. Then click Execute.

enter image description here

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.

恬淡成诗 2024-10-29 18:27:38

如果你想重置你的表,你可以执行

truncate table TableName

truncate 需要特权,并且如果你的表有依赖项(另一个具有你的表的 FK 的表,

If you want to reset your table, you can do

truncate table TableName

truncate needs privileges, and you can't use it if your table has dependents (another tables that have FK of your table,

我的痛♀有谁懂 2024-10-29 18:27:38

对于一张表

truncate table [table name]

对于所有表

EXEC sp_MSforeachtable @command1="truncate table ?"

For one table

truncate table [table name]

For all tables

EXEC sp_MSforeachtable @command1="truncate table ?"
陪我终i 2024-10-29 18:27:38

如果要删除数据库中的记录,请删除“结果”窗格中的行。如果要删除所有行,可以使用删除查询。

Delete from Table_name

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.

Delete from Table_name
俯瞰星空 2024-10-29 18:27:38
delete from TableName

这不是一个好的做法。

就像在 Google BigQuery 中一样,它不允许在没有“where”子句的情况下使用删除。

改用

truncate table TableName

delete from TableName

isn't a good practice.

Like in Google BigQuery, it don't let to use delete without "where" clause.

use

truncate table TableName

instead

提笔书几行 2024-10-29 18:27:38

当表很大时,如果有建表查询,最好使用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, using delete from statement because that can be time consuming.

如此安好 2024-10-29 18:27:38

如果您愿意以合理的权限删除所有记录,则语句为 DELETE FROM YourDatabaseName.SomeTableName;。但是您可能会在为外键定义的约束中看到错误。因此,您需要在删除记录之前更改约束,否则 MySQL 有一个命令(可能对其他人有效)来忽略约束。

SET foreign_key_checks = 0;

请注意,此命令将禁用外键约束检查,因此这对于您在架构中创建的关系可能很危险。

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.

SET foreign_key_checks = 0;

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文