博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
A2-02-29.DML-MySQL DELETE
阅读量:4602 次
发布时间:2019-06-09

本文共 2769 字,大约阅读时间需要 9 分钟。

转载自:

MySQL DELETE

 

Summary: in this tutorial, you will learn how to use the MySQL DELETE statement to delete data from a single table.

Introduction to MySQL DELETE statement

To delete data from a table, you use the MySQL DELETE statement. The following illustrates the syntax of the DELETE statement:

In this statement:

  • First, specify the table from which you delete data.
  • Second, use a condition to specify which rows to delete in the WHERE clause. If the row matches the condition, it will be deleted.

Notice that the WHERE clause is optional. If you omit the WHERE clause, the DELETE statement will delete all rows in the table.

Besides deleting data from a table, the DELETE statement returns the number of rows deleted.

To delete data from multiple tables using a single DELETE statement, you use the  statement which we will cover in the .

To delete all rows in a table without the need of knowing how many rows deleted, you should use the  statement to get a better performance.

For a table that has a  constraint, when you delete rows from the parent table, the rows in the child table will be deleted automatically by using the  option.

MySQL DELETE examples

We will use the employees table in the  for the demonstration.

MySQL DELETE - Employees Table

Note that once you delete data, it is gone. Therefore, you should   before performing the 
DELETE statements in the next section.

Suppose you want to delete employees whose officeNumber is 4, you use the DELETE statement with the  clause as the following query:

To delete all rows from the employees table, you use the DELETE statement without the WHERE clause as follows:

All rows in the employees table deleted.

MySQL DELETE and LIMIT clause

If you want to limit the number of rows to be deleted, you use the  clause as follows:

Note that the order of rows in a table is unspecified, therefore, when you use the LIMIT clause, you should always use the  clause.

Consider the following customers table in the :

For example, the following statement sorts customers by customer’s names alphabetically and deletes the first 10 customers:

Similarly, the following DELETE statement selects customers in France, sorts them by credit limit in ascending order, and deletes the first 5 customers:

In this tutorial, you have learned how to use the MySQL DELETE statement to delete data from a table.

转载于:https://www.cnblogs.com/zhuntidaoren/p/9519497.html

你可能感兴趣的文章
Asp.net(C#) windows 服务{用于实现计划任务,事件监控等}
查看>>
pod search 特别慢或者搜索不到
查看>>
Codeforces Round #377 (Div. 2)D(二分)
查看>>
get请求和post请求的区别
查看>>
LAMP网站架构方案分析
查看>>
linux常用命令整理
查看>>
【hihocoder】01背包
查看>>
HBase权威指南中文版pdf
查看>>
windows下svn备份(详解)
查看>>
OO第二次博客作业
查看>>
pku 2965 The Pilots Brothers' refrigerator 第一周训练之枚举
查看>>
CROC-MBTU 2012, Elimination Round (ACM-ICPC) H DP题目
查看>>
(转载)将h.264视频流封装成flv格式文件(二.开始动手)http://blog.csdn.net/yeyumin89/article/details/7932431...
查看>>
项目源码--IOS自定义视频播放器
查看>>
xutil3 post 和 get请求
查看>>
solusvm 主控端迁移
查看>>
图论最短路径算法——Dijkstra
查看>>
vscode 快速生成html
查看>>
SignalR Connection has not been fully initialized
查看>>
使用pycharm开发web——django2.1.5(三)创建models并进入交互界面shell做一些简单操作...
查看>>