Oracle 主键、联合主键的查询与创建

--查询某个表是否有唯一主键

select cu.* from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and au.constraint_type = 'P' and au.table_name ='表名'

--查询某个表是否有联合主键

select cu.* from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and au.constraint_type = 'U' and au.table_name ='表名'

 

--创建唯一主键

alter table 表名 add constraint pk_table primary key(id); --pk_table 是指 主键的名称,而括号里的 id是指表的唯一主键

 

--创建联合主键

alter table 表名 add constraint ak_table unique(name,age,sex); --ak_table 是指 联合主键的名称,而括号里的 name,age,sex是指表的联合主键

posted on 2014-09-04 13:48  小人物大梦想  阅读(2880)  评论(0编辑  收藏  举报

导航