sql delete语句_SQL Delete语句概述

sql delete语句

This article on the SQL Delete is a part of the SQL essential series on key statements, functions and operations in SQL Server.

有关SQL Delete的这篇文章是有关SQL Server中关键语句,函数和操作SQL基本系列的一部分。

To remove a row from a table is accomplished through a Data Manipulation Language, aka DML statement, using the delete keyword. The SQL delete operation is by far the simplest of all the DML commands. On execution of the delete command, we don’t have to worry about getting any form of data from the table, and we don’t have to worry about working with any data that we get back from the table(s). We just simply tell the database to delete a specific record, and it either does or it doesn’t. It’s that simple.

从表中删除行是通过数据操作语言(又称DML语句)使用delete关键字完成的。 到目前为止,SQL删除操作是所有DML命令中最简单的操作。 在执行delete命令时,我们不必担心从表中获取任何形式的数据,也不必担心处理从表中获取的任何数据。 我们只是简单地告诉数据库删除特定记录,它要么执行,要么不执行。 就这么简单。

First, let’s quickly review what an SQL delete statement looks like. We need to tell the database and table from where it should delete the data. It’s a good idea to add a condition clause to set the scope of data deletion. Otherwise, it will delete everything in the table.

首先,让我们快速回顾一下SQL delete语句的外观。 我们需要告诉数据库和表应从何处删除数据。 添加条件子句以设置数据删除的范围是一个好主意。 否则,它将删除表中的所有内容。

Let’s take a look at our table and removing some records.

让我们看一下表并删除一些记录。

如何删除不带where子句的行 (How to delete rows with no where clause)

The following example deletes all rows from the Person.Person the table in the AdventureWorks2014 database. There is no restriction enforced on the SQL delete statement using a WHERE clause.

下面的示例从AdventureWorks2014数据库中的Person.Person表中删除所有行 。 使用WHERE子句SQL delete语句没有任何限制。

USE Adventureworks2014;
GO
DELETE FROM [Person].[Person];

如何使用where子句删除行 (How to delete rows with where clause)

The following example deletes rows from the [Person].[Person] table in the AdventureWorks2014 database in which the value in the businessEntityID column is greater than 30,000

以下示例从AdventureWorks2014数据库的[Person]。[Person]表中删除行,其中businessEntityID列中的值大于30,000

USE Adventureworks2014;
GO
DELETE FROM [Person].[Person]
WHERE businessEntityID > 30000;

Note: An unfortunate mistake that may occur is to accidently run a SQL Delete with no Where clause and inadvertently delete all of your data. To prevent this from happening consider using the Execution guard feature in ApexSQL Complete, to warn against such potentially damaging actions, before you execute them. Learn more: Execution alerts

注意:可能发生的不幸错误是意外地运行了不带Where子句SQL Delete并无意间删除了所有数据。 为防止这种情况发生,请在执行之前考虑使用ApexSQL Complete中的Execution保护功能,以警告此类可能有害的操作。 了解更多: 执行警报

如何使用带有where子句的Top删除行 (How to delete rows using Top wi

你可能感兴趣的:(数据库,python,mysql,java,sql)