从 MySQL 数据库删除带有特定域的 URL?


要删除有特定域的 URL,请使用 DELETE 和 LIKE 子句。

让我们首先创建一个表 −

mysql> create table DemoTable1361
    -> (
    -> URL text
    -> ) ;
Query OK, 0 rows affected (0.58 sec)

使用 insert 命令在表中插入一些记录 −

mysql> insert into DemoTable1361 values('Https://www.google.com//?id=1');
Query OK, 1 row affected (0.21 sec)
mysql> insert into DemoTable1361 values('https://#//?id=2&name=John');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable1361 values('Https://www.yahoo.com//?id=3');
Query OK, 1 row affected (0.31 sec)
mysql> insert into DemoTable1361 values('Https://www.google.com//?id=1');
Query OK, 1 row affected (0.16 sec)

使用 select 语句显示表中的所有记录 −

mysql> select * from DemoTable1361;

这将产生以下输出 −

+-------------------------------------------+
| URL                                       |
+-------------------------------------------+
| Https://www.google.com//?id=1             |
| https://#//?id=2&name=John |
| Https://www.yahoo.com//?id=3              |
| Https://www.google.com//?id=1             |
+-------------------------------------------+
4 rows in set (0.00 sec)

以下是如何从 MySQL 数据库中删除具有特定域的 URL 的查询 −

mysql> delete from DemoTable1361 where URL LIKE '%Https://www.google.com%';
Query OK, 2 rows affected (0.17 sec)

让我们再次检查表记录 −

mysql> select * from DemoTable1361;

这将产生以下输出 −

+-------------------------------------------+
| URL                                       |
+-------------------------------------------+
| https://#//?id=2&name=John |
| Https://www.yahoo.com//?id=3              |
+-------------------------------------------+
2 rows in set (0.00 sec)

更新于: 08-11-2019

250 次浏览

启动您的 职业生涯

完成课程即可获得认证

开始吧
广告
© . All rights reserved.