MySQL查询删除行
使用DELETE删除MySQL中的一行。让我们首先创建一个表-
create table DemoTable(
CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
CustomerName varchar(100),
CustomerAge int
);
使用插入命令在表中插入一些记录-
insert into DemoTable(CustomerName,CustomerAge) values('John',33);insert into DemoTable(CustomerName,CustomerAge) values('Bob',25);
insert into DemoTable(CustomerName,CustomerAge) values('David',28);
insert into DemoTable(CustomerName,CustomerAge) values('Carol',29);
使用select语句显示表中的所有记录-
select *from DemoTable;
输出结果
这将产生以下输出-
+------------+--------------+-------------+| CustomerId | CustomerName | CustomerAge |
+------------+--------------+-------------+
| 1 | John | 33 |
| 2 | Bob | 25 |
| 3 | David | 28 |
| 4 | Carol | 29 |
+------------+--------------+-------------+
4 rows in set (0.00 sec)
以下是在MySQL中删除行的查询-
delete from DemoTable where CustomerName='David' and CustomerAge=28;
让我们再次检查表记录-
select *from DemoTable;
输出结果
这将产生以下输出-
+------------+--------------+-------------+| CustomerId | CustomerName | CustomerAge |
+------------+--------------+-------------+
| 1 | John | 33 |
| 2 | Bob | 25 |
| 4 | Carol | 29 |
+------------+--------------+-------------+
3 rows in set (0.00 sec)
以上是 MySQL查询删除行 的全部内容, 来源链接: utcz.com/z/317189.html