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. vue项目用webpack打包后跨域问题

    在app.js的最开始加上 app.all('*', (req, res, next) => { res.header("Access-Control-Allow-Origin&quo ...

  2. ansys14.0 从入门到精通

    凌桂龙 李战分 2013.2 清华大学 FLUENT流体计算应用教程 索书号:TB126-39 ZW2.1     单元 结点 和 自由度 载荷 与 边界条件 : 关系 就是约束 , 边界条件是 结构 ...

  3. C#生成二維碼(ThoughtWorks.QRCode)

    本人使用的是ThoughtWorks.QRCode.dll,在網上可以下載,但要注意dll文件的完整性和準確性,本人之前下載的dll就是不正確導致調試時出現錯誤. 以下為cs文件代碼: using S ...

  4. Kafka消费不到数据的特殊情况

    我大约是把kafka消费不到数据的特殊情况都经历了一遍了吧= =. kafka消费不到数据的原因,首先检查配置之类的,如是否设置了group.id,对应的topic是否正确等等,这些不多说. 下面是我 ...

  5. mysql 显示树结构表的节点全路径

    SELECT TYPEID AS TYPEID, pTYPEID AS 父TYPEID, levels AS 父到子之间级数, concat(paths, ',', TYPEID) AS 父到子路径, ...

  6. OSG DB的插件地址设置

    今天搞了一整天OSG,结果每次都说could not find plugin,就是说找不到OSG的插件去加载文件,我大概看了下OSG的插件机制,发现他是用插件的形式下去读取文件的 http://blo ...

  7. (转)PEP 8——Python编码风格指南

    PEP 8——Python编码风格指南标签(空格分隔): Python PEP8 编码规范原文:https://lizhe2004.gitbooks.io/code-style-guideline-c ...

  8. 深入浅出理解linux inode结构

    一.inode是什么? 参考文档:http://tech.diannaodian.com/dw/lin/2012/0112/154629.html 做Android底层驱动或者嵌入式Linux的程序猿 ...

  9. 案例45-crm练习改写客户列表使用struts2&OGNL

    1 修改CustomerAction代码 2 修改jsp/customer/list.jsp代码 <%@ page language="java" contentType=& ...

  10. 在lua中解决if else switch问题

    之前写过一个c#版本的使用字典去解决switch问题  http://www.cnblogs.com/sanyejun/p/7806210.html 现在用写lua版本的 function Main( ...