本文介绍了SQL查询找到表的主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过使用查询查找表的主键的哪一列?
How can I find which column is the primary key of a table by using a query?
推荐答案
对于Oracle,您可以在 ALL_CONSTRAINTS
表:
For Oracle, you can look it up in the ALL_CONSTRAINTS
table:
SELECT a.COLUMN_NAME
FROM all_cons_columns a INNER JOIN all_constraints c
ON a.constraint_name = c.constraint_name
WHERE c.table_name = 'TBL'
AND c.constraint_type = 'P';
演示 .
DEMO.
对于SQL Server,已经在此处进行了回答,对于MySQL,请检查@ajon的答案.
For SQL Server, it was already answered here, and for MySQL check @ajon's answer.
这篇关于SQL查询找到表的主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!