为此,您可以使用DELETE命令。让我们首先创建一个表-
mysql> create table DemoTable1 ( Id int, Name varchar(20) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1 values(1,'Chris'); mysql> insert into DemoTable1 values(2,'David'); mysql> insert into DemoTable1 values(3,'Bob');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable1;
这将产生以下输出-
+------+-------+ | Id | Name | +------+-------+ | 1 | Chris | | 2 | David | | 3 | Bob | +------+-------+ 3 rows in set (0.00 sec)
这是创建第二个表的查询-
mysql> create table DemoTable2 ( ClientId int, ClientName varchar(20) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable2 values(101,'Mike'); mysql> insert into DemoTable2 values(110,'Bob'); mysql> insert into DemoTable2 values(120,'Adam');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable2;
这将产生以下输出-
+----------+------------+ | ClientId | ClientName | +----------+------------+ | 101 | Mike | | 110 | Bob | | 120 | Adam | +----------+------------+ 3 rows in set (0.00 sec)
这是多表删除的查询-
mysql> delete from DemoTable1 where Name='Bob'; mysql> delete from DemoTable2 where ClientName='Bob';
让我们检查第一个表记录-
mysql> select *from DemoTable1;
这将产生以下输出-
+------+-------+ | Id | Name | +------+-------+ | 1 | Chris | | 2 | David | +------+-------+ 2 rows in set (0.00 sec)
让我们检查第二个表记录-
mysql> select *from DemoTable2;
这将产生以下输出-
+----------+------------+ | ClientId | ClientName | +----------+------------+ | 101 | Mike | | 120 | Adam | +----------+------------+ 2 rows in set (0.00 sec)