查询Oracle表的PK列

gjwang1983 2009-07-01 01:13:06
数据库在Unix Server上,我通过终端sqlplus登陆后,想查询一个数据库里的某张表的PK列。请问如何查询?
$sqlplus username/password@tnsname
SQL> desc table_1
a number(38)
b varchar(100)
SQL> how to query the PK columns of table_1 ?
...全文
227 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
inthirties 2009-07-01
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 superhsj 的回复:]
SQL code
select * from user_cons_columns where constraint_name=
(select constraint_name from user_constraints where table_name = '表名大写' and constraint_type ='P');


[/Quote]

这个不错
superhsj 2009-07-01
  • 打赏
  • 举报
回复
select * from user_cons_columns where constraint_name= 
(select constraint_name from user_constraints where table_name = '表名大写' and constraint_type ='P');
suncrafted 2009-07-01
  • 打赏
  • 举报
回复

SELECT T.OWNER,T.TABLE_NAME,T.CONSTRAINT_NAME AS PRI_KEY FROM ALL_CONSTRAINTS T
WHERE T.OWNER = UPPER('username')
AND T.TABLE_NAME = UPPER('table_1')
AND T.CONSTRAINT_TYPE = 'P'

17,380

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧