此命令显示表格。
mysql> show tables like '%xyz%';
+------------------------------+
| Tables_in_XYZ (%xyz%) |
+------------------------------+
| xyz2 |
| xyz23 |
| xyz23_linuxLineEnding |
+------------------------------+
3 rows in set (0.00 sec)
有什么命令可以在每个表中插入索引编号,例如
+----+------------------------------+
| id | Tables_in_XYZ (%xyz%) |
+----+------------------------------+
| 1 | xyz2 |
| 2 | xyz23 |
| 3 | xyz23_linuxLineEnding |
+----+------------------------------+
mysql> select (@rn := @rn + 1) as id, table_name from information_schema.tables where table_name LIKE '%xyz%';
+------+-----------------------+
| id | table_name |
+------+-----------------------+
| NULL | xyz2 |
| NULL | xyz23 |
| NULL | xyz23_linuxLineEnding |
+------+-----------------------+
3 rows in set (0.00 sec)
mysql> set @rn :=0;
Query OK, 0 rows affected (0.00 sec)
mysql> select (@rn := @rn + 1) as id, table_name from information_schema.tables where table_name LIKE '%xyz%';
+------+-----------------------+
| id | table_name |
+------+-----------------------+
| 1 | xyz2 |
| 2 | xyz23 |
| 3 | xyz23_linuxLineEnding |
+------+-----------------------+
3 rows in set (0.00 sec)
答案 0 :(得分:1)
您可以使用information_schema.tables
:
select (@rn := @rn + 1) as id, table_name
from information_schema.tables cross join
(select @rn := 0) params
where table_name like '%xyz%';