我有一个mysql数据库,我想拉出所有表及其相应的列名。我设法使用以下方法执行此操作:
SELECT `TABLE_NAME`, `COLUMN_NAME`
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`='Database';
但我只希望所有行都没有Null的列,我厌倦了以下但是这不起作用:
SELECT `TABLE_NAME`, `COLUMN_NAME`
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`='Database' AND `COLUMN_NAME` IS NOT NULL;
但结果与我之前的查询相同
数据库中样本表的结构:
ID Entity_ID Balance Security Purpose
A1 ADF1 32131 412 NULL
A2 JFJ4 51551 NULL NULL
答案 0 :(得分:2)
试试这个:
SELECT `TABLE_NAME`, `COLUMN_NAME`
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`='Database' AND `IS_NULLABLE` = 'NO';
答案 1 :(得分:1)
我希望它会有所帮助。
SELECT `TABLE_NAME`,`COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`='Database' AND `COLUMN_NAME`<>NULL;