获取有关约束的完整信息
我想创建结果如下的查询:
column_name, constraint_name, constraint_type, referenced_table_name, referenced_column_name
我尝试过类似的操作
SELECT col.column_name, cons.constraint_name, cons.constraint_type,col.referenced_table_name, col.referenced_column_name
FROM information_schema.table_constraints cons, information_schema.key_column_usage col
WHERE col.table_name = 'countries'
AND cons.constraint_name = col.constraint_name
AND cons.table_name = col.table_name
,但是我得到了错误的column_name...:(
请帮助我...
I want to create query that result like this :
column_name, constraint_name, constraint_type, referenced_table_name, referenced_column_name
I have try something like this
SELECT col.column_name, cons.constraint_name, cons.constraint_type,col.referenced_table_name, col.referenced_column_name
FROM information_schema.table_constraints cons, information_schema.key_column_usage col
WHERE col.table_name = 'countries'
AND cons.constraint_name = col.constraint_name
AND cons.table_name = col.table_name
but, I get wrong column_name... :(
please help me...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道
constraint_type
。我在 information_schema 中没有找到此列。I don't know about
constraint_type
. I haven't found this column in information_schema.主键的名称始终为“PRIMARY”,外键的名称始终为referenced_table_name,因此您可以从一个表中获取该信息 -
key_column_usage
:Primary keys always have name 'PRIMARY', foreign keys always have referenced_table_name, so you can get that info from one table -
key_column_usage
: