oracle获取表的主键列 [英] Get primary key column of a table in oracle

查看:71
本文介绍了oracle获取表的主键列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用 Oracle 完全陌生,所以我可能没有使用正确的术语.请原谅我.

I am totally new to using Oracle so I might not be using the right terminologies. Please excuse me for that.

我有以下查询可以帮助我获取 SQL Server 中表的主键

I have the following query which helps me get the Primary key of a table in 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'

所以我想要类似的东西,它可以帮助我获取具有主键的表的列名.提前致谢

So I want something similar which can help me get the column name of the table which has the primary key. Thanks in advance

推荐答案

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您的表格

NOTE replace TABLE_NAME in upper case your table

这篇关于oracle获取表的主键列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆