简体   繁体   English

描述MYSQL中所有表的主键

[英]Desc primary key of all tables in MYSQL

I want to get the result of Desc for only specific columns of each table in the information schema, let's say Primary Key. 我只想获取信息模式中每个表的特定列的Desc结果,例如主键。

Can this be done? 能做到吗?

I tried things like 我尝试过类似的事情

 SELECT * FROM (DESC TABLENAME) WHERE ....;

but it did not work. 但它没有用。

Also I want this to work for all tables. 我也希望这适用于所有表。

DESC aka DESCRIBE aka SHOW COLUMNS will not work in a subquery. DESC aka DESCRIBE aka SHOW COLUMNS在子查询中将不起作用。 But SELECT will. 但是SELECT会。 You can for example replace 您可以例如替换

SHOW COLUMNS FROM t IN test LIKE '%2';

with

SELECT column_name AS `Field`, column_type AS `Type`,
is_nullable AS `Null`,
column_key as 'Key',
column_default AS `Default`, extra AS `Extra`
FROM information_schema.columns
WHERE table_schema = 'test'
AND table_name = 't'
AND column_name like '%2';

and you'll get the same thing. 你会得到同样的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM