当前位置:网站首页>9、学习MySQL DELETE 语句
9、学习MySQL DELETE 语句
2022-07-26 14:35:00 【微服务 spring cloud】
MySQL DELETE 语句
你可以使用 SQL 的 DELETE FROM 命令来删除 MySQL 数据表中的记录。
你可以在 mysql> 命令提示符或 PHP 脚本中执行该命令。
语法
以下是 SQL DELETE 语句从 MySQL 数据表中删除数据的通用语法:
DELETE FROM table_name [WHERE Clause]- 如果没有指定 WHERE 子句,MySQL 表中的所有记录将被删除。
- 你可以在 WHERE 子句中指定任何条件
- 您可以在单个表中一次性删除记录。
当你想删除数据表中指定的记录时 WHERE 子句是非常有用的。
从命令行中删除数据
这里我们将在 SQL DELETE 命令中使用 WHERE 子句来删除 MySQL 数据表 xxxxxx_tbl 所选的数据。 需要框架源码的朋友可以看我个人简介联系我。

实例
以下实例将删除 xxxxxx_tbl 表中 xxxxxx_id 为3 的记录:
DELETE 语句:
mysql> use XXXXXX;
Database changed
mysql> DELETE FROM xxxxxx_tbl WHERE xxxxxx_id=3;
Query OK, 1 row affected (0.23 sec)使用 PHP 脚本删除数据
PHP使用 mysqli_query() 函数来执行SQL语句, 你可以在 SQL DELETE 命令中使用或不使用 WHERE 子句。
该函数与 mysql> 命令符执行SQL命令的效果是一样的。
实例
以下PHP实例将删除 xxxxxx_tbl 表中 xxxxxx_id 为 3 的记录:
MySQL DELETE 子句测试:
<?php
$dbhost = 'localhost'; // mysql服务器主机地址
$dbuser = 'root'; // mysql用户名
$dbpass = '123456'; // mysql用户名密码
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('连接失败: ' . mysqli_error($conn));
}
// 设置编码,防止中文乱码
mysqli_query($conn , "set names utf8");
$sql = 'DELETE FROM xxxxxx_tbl
WHERE xxxxxx_id=3';
mysqli_select_db( $conn, 'XXXXXXX' );
$retval = mysqli_query( $conn, $sql );
if(! $retval )
{
die('无法删除数据: ' . mysqli_error($conn));
}
echo '数据删除成功!';
mysqli_close($conn);
?>边栏推荐
- 中值滤波器
- SSH that must be read on cloud native
- Siamrpn++: evolution of deep network connected visual tracking
- AMB | 迈向可持续农业:根际微生物工程
- Simple implementation of pytorch
- [file upload vulnerability-06] distributed configuration file attack experiment - take upload-labs-4 as an example
- Winscp transfer file and VNC connection problem
- What is restful style and its four specific implementation forms
- Low power multi-channel wfas1431 wireless data acquisition and transmission instrument operation process description
- maya将模型导入到unity
猜你喜欢

Usage of nn.conv2d and nn.convtranspose2d functions in pytorch

llcc68广播唤醒简单说明

【无标题】

Summary and analysis of image level weakly supervised image semantic segmentation
Network pictures are transferred locally, causing the kernel to exit

SA-Siam:用于实时目标跟踪的孪生网络

Create Yum warehouse inside the enterprise

sp导出贴图到maya

Maya imports the model into unity
![Matlab solution of [analysis of variance]](/img/30/638c4671c3e37b7ce999c6c98e3700.png)
Matlab solution of [analysis of variance]
随机推荐
As the "first city" in Central China, Changsha's "talent attraction" has changed from competition to leadership
【文件上传漏洞-06】分布式配置文件攻击实验—以upload-labs-4为例
31. Opinion-based Relational Pivoting forCross-domain Aspect Term Extraction 阅读笔记
Pdf translation, which translation company in Beijing is good
Transc knowledge representation model
.net6 encounter with the League of heroes - create a game assistant according to the official LCU API
10 schemes to ensure interface data security
C语言入门必刷100题合集之每日一题(1-20)
Create Yum warehouse inside the enterprise
保证接口数据安全的10种方案
Image-Level 弱监督图像语义分割汇总简析
C winfrom common function integration
WPF 常用功能整合
Use of URL download resources
[dry goods] data structure and algorithm principle behind MySQL index
Low power multi-channel wfas1431 wireless data acquisition and transmission instrument operation process description
基于CAS的SSO单点服务端配置
『BaGet』带你一分钟搭建自己的私有NuGet服务器
What is restful style and its four specific implementation forms
Keyboard shortcut to operate the computer (I won't encounter it myself)