<!--[if !supportLists]-->1.<!--[endif]-->建主键约束(表名为AN)
Alter table an add constraint PK_AN primary key(ID);
<!--[if !supportLists]-->2.<!--[endif]-->建联合主键
Alter table an add constraint PK_AN primary key(ID,NAME);
<!--[if !supportLists]-->3.<!--[endif]-->创建表描述
Comment on table an is ‘表含义’;
<!--[if !supportLists]-->4.<!--[endif]-->创建字段描述
Comment on column an.id is ‘字段含义’;
<!--[if !supportLists]-->5.<!--[endif]-->建外键
Alter table an_1 add constraint FK_AN_1 foreign key(an_id) references AN(ID);
<!--[if !supportLists]-->6.<!--[endif]-->查看表的主键
SELECT * FROM USER_CONS_COLUMNS cc,USER_CONSTRAINTS c WHERE c.constraint_name=cc.constraint_name
AND c.constraint_type='P' AND cc.table_name='AN';
<!--[if !supportLists]-->7.<!--[endif]-->查看外键
SELECT r.constraint_name,r.r_constraint_name,rc.column_name,pc.column_name AS PK_COLUMN_NAME,pc.table_name AS PK_TABLE_NAME
FROM USER_CONSTRAINTS r,USER_CONS_COLUMNS rc,USER_CONSTRAINTS p,USER_CONS_COLUMNS pc
WHERE r.constraint_type='R' AND r.constraint_name=rc.constraint_name AND pc.constraint_name=p.constraint_name
AND p.constraint_type='P' AND r.r_constraint_name=p.constraint_name AND r.table_name='APAS_SERVICE';
<!--[if !supportLists]-->7.<!--[endif]-->删除主键
alter table an drop constraint constraint_name;
<!--[if !supportLists]-->8.<!--[endif]-->使主键失效
alter table an disable constraint constraint_name;
<!--[if !supportLists]-->9.<!--[endif]-->使主键生效
alter table an ensable constraint constraint_name;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30461945/viewspace-1807360/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/30461945/viewspace-1807360/