SQL DELETE Statement


The SQL DELETE Statement

The DELETE statement is used to delete existing records in a table.

DELETE Syntax

DELETE FROM table_name
WHERE condition;

Note: Be careful when deleting records in a table! Notice the WHERE clause in the DELETE statement. The WHERE clause specifies which record(s) that should be deleted. If you omit the WHERE clause, all records in the table will be deleted!


Demo Database

Below is a selection from the "Customers" table in the Northwind sample database:

CustomerID CustomerName ContactName Address City PostalCode Country
1

Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 12209 Germany
2 Ana Trujillo Emparedados y helados Ana Trujillo Avda. de la Constitución 2222 México D.F. 05021 Mexico
3 Antonio Moreno Taquería Antonio Moreno Mataderos 2312 México D.F. 05023 Mexico
4

Around the Horn Thomas Hardy 120 Hanover Sq. London WA1 1DP UK
5 Berglunds snabbköp Christina Berglund Berguvsvägen 8 Luleå S-958 22 Sweden

 

SQL DELETE Example

The following SQL statement deletes the customer "Alfreds Futterkiste" from the "Customers" table:

Example

DELETE FROM Customers
WHERE CustomerName='Alfreds Futterkiste';

The "Customers" table will now look like this:

CustomerID CustomerName ContactName Address City PostalCode Country
2 Ana Trujillo Emparedados y helados Ana Trujillo Avda. de la Constitución 2222 México D.F. 05021 Mexico
3 Antonio Moreno Taquería Antonio Moreno Mataderos 2312 México D.F. 05023 Mexico
4

Around the Horn Thomas Hardy 120 Hanover Sq. London WA1 1DP UK
5 Berglunds snabbköp Christina Berglund Berguvsvägen 8 Luleå S-958 22 Sweden

Delete All Records

It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be intact:

DELETE FROM table_name;

or:

DELETE * FROM table_name;

Delete All Null Records

delete * from emp where comm is null;

delect *  from emp where comm='';

CREATE OR REPLACE PROCEDURE emp01_delete_null AS
BEGIN
DELETE FROM emp01 WHERE comm IS NULL;
COMMIT;
END emp01_delete_null; execute emp01_delete_null;

ORACLE_DELETE的更多相关文章

随机推荐

  1. P3332 [ZJOI2013]K大数查询

    传送门 注意操作 $1$ 是在区间的每个位置加入一个数,不是加上一个值 相当于每个位置维护的是一个集合 显然树套树 一开始想的是区间线段树套权值线段树 发现这样询问区间第 $K$ 大时就要先二分答案再 ...

  2. 选择排序 Selection Sort

    选择排序 Selection Sort 1)在数组中找最小的数与第一个位置上的数交换: 2)找第二小的数与第二个位置上的数交换: 3)以此类推 template<typename T> / ...

  3. setlocal enabledelayedexpansion 解释

    看字面的意思是:设置本地为延迟扩展.其实也就是:延迟变量,全称"延迟环境变量扩展", 在cmd执行命令前会对脚本进行预处理,其中有一个过程是变量识别过程,在这个过程中,如果有两个% ...

  4. [转] Tomcat 禁用URL中的JSESSIONID

    [From] http://stackoverflow.com/questions/962729/is-it-possible-to-disable-jsessionid-in-tomcat-serv ...

  5. rancher初级(搭建+基本操作+web应用部署)

    Rancher搭建 首先rancher需要安装了docker的linux环境,我的系统版本为 在docker的基础上启动rancher服务器,Rancher 服务器是一个 Docker image,所 ...

  6. do while循环

    do while循环: 语法格式: do{ 循环体 }while(循环条件); 执行流程: 先执行循环体,然后判断条件,当条件为true时,则继续执行循环体,然后再判断条件... 一直到循环条件为fa ...

  7. angular的基本要点

    <body ng-app="Myapp"> <div ng-controller="firstcon"> <h1>hello ...

  8. [转]ClassPath是什么

    from: https://my.oschina.net/GivingOnenessDestiny/blog/603505 classpath 是什么classpath实际上就是编译后的 以 clas ...

  9. 让C:\Users文件夹放在D盘

    新安装win7 在安装Win7的过程中,要求输入用户名及密码的时候,先不如输入任何信息,按“Shift+F10”呼出DOS窗口,输入以下命令: robocopy "C:\Users" ...

  10. mongoDB cpu飙高问题

    问题描述: 最近几天生产环境上的mongodb一直在报警,cpu飙高,其他如内存.iops.连接数.磁盘操作等都正常.通过定位业务,发现是由于mongodb的表其中一个查询未建立索引导致,110多W的 ...