select COLUMN_NAME from information_schema.COLUMNS where table_name = 'your_table_name'
上述的做法有一点问题,如果多个数据库中存在你想要查询的表名,那么查询的结果会包括全部的字段信息。通过DESC information_schema.COLUMNS可以看到该表中列名为TABLE_SCHEMA是记录数据库名,因此下面的写法更为严格
select COLUMN_NAME from information_schema.COLUMNS where table_name = 'your_table_name' and table_schema = 'your_db_name'
在Mysql 众多表中查找一个表名或者字段名的 SQL 语句:SELECT table_name, column_name from information_schema.columns WHERE column_name LIKE 'Name'
下面两种方法也可以查到:
红色代表可选项
SELECT column_name from information_schema.columns WHERE (column_name LIKE ’%searchTerm%’ AND) table_schema = ‘yourDB’
SELECT column_name from information_schema.columns WHERE (column_name LIKE ’%searchTerm%’ AND) table_schema = ‘yourDB’ AND table_name = ‘yourDBTable’
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)