我对使用Oracle完全不熟悉所以我可能没有使用正确的术语。请原谅我。
我有以下查询帮助我获取SQL Server中表的主键
SELECT Col.Column_Name, Tab.Table_Name from
INFORMATION_SCHEMA.TABLE_CONSTRAINTS Tab,
INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE Col
WHERE Col.Constraint_Name = Tab.Constraint_Name
AND Col.Table_Name = Tab.Table_Name
AND Constraint_Type = 'PRIMARY KEY'
AND Col.Table_Name = 'EmployeeMaster'
所以我想要类似的东西,这可以帮助我获得具有主键的表的列名。提前致谢
答案 0 :(得分:2)
SELECT cols.table_name, cols.column_name, cols.position, cons.status, cons.owner
FROM all_constraints cons, all_cons_columns cols
WHERE cols.table_name = 'TABLE_NAME'
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
ORDER BY cols.table_name, cols.position;
注意以大写字母替换TABLE_NAME 您的表格