mysql中如何查询数据库中的表名
吾爱主题
阅读:177
2022-12-22 16:51:00
评论:0
查询数据库中的表名
查询一个数据库中含有某关键词的表名
搜索一个数据库中包含一些关键字,词的表。
?1 2 3 4 5 6 7 | SELECT TABLE_NAME FROM information_schema. TABLES WHERE table_schema = '数据库名' AND TABLE_NAME LIKE '%name%' ; |
例:
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | mysql> select table_name from information_schema.tables -> where table_schema = 'sakila' -> and table_name like "%film%" ; + ----------------------------+ | TABLE_NAME | + ----------------------------+ | film | | film_actor | | film_category | | film_list | | film_text | | nicer_but_slower_film_list | | sales_by_film_category | + ----------------------------+ 7 rows in set (0.00 sec) |
查询数据库中所有的表
?1 2 3 4 | show tables; -- use 数据库名 USE sakila; SHOW TABLES; |
同上面,where条件只查数据库名。还可以同时搜索多个数据库中的表。
?1 2 3 4 5 6 | SELECT TABLE_NAME FROM information_schema. TABLES WHERE table_schema = '数据库名' ; |
例:
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | mysql> select table_name from information_schema.tables where table_schema = 'sakila' ; + ----------------------------+ | TABLE_NAME | + ----------------------------+ | actor | | actor_info | | address | | category | | city | | country | | customer | | customer_list | | film | | film_actor | | film_category | | film_list | | film_text | | inventory | | language | | nicer_but_slower_film_list | | payment | | rental | | sales_by_film_category | | sales_by_store | | staff | | staff_list | | store | + ----------------------------+ 23 rows in set (0.00 sec) mysql> select table_name from information_schema.tables where table_schema = 'sakila' or table_schema = 'test' ; + ----------------------------+ | TABLE_NAME | + ----------------------------+ | actor | | address | | category | | city | | country | | customer | | film | | film_actor | | film_category | | film_text | | inventory | | language | | payment | | rental | | staff | | store | | customer_list | | film_list | | nicer_but_slower_film_list | | staff_list | | sales_by_store | | sales_by_film_category | | actor_info | | employee | | test_alter | + ----------------------------+ 25 rows in set (0.01 sec) |
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/Olivia_Vang/article/details/103172800
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。