文档课题:验证oracle创建唯一键后索引的自动生成.标签:test2,NAME,键后,HR,索引,orcl150,oracle,table,name From: https://blog.51cto.com/u_12991611/6029891
数据库:oracle 11.2.0.4
1、原表数据
HR@orcl150> DESC test2;
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER(4)
NAME VARCHAR2(20)
HR@orcl150> select * from test2;
ID NAME
---------- --------------------
1 henrry
2、添加约束
HR@orcl150> alter table test2 add constraint indx_test2_id unique (id) enable novalidate;
Table altered.
3、数据验证
HR@orcl150> col owner for a10
HR@orcl150> col CONSTRAINT_NAME for a20
HR@orcl150> col TABLE_NAME for a15
HR@orcl150> set line 200
HR@orcl150> select owner,constraint_name,constraint_type,table_name from user_constraints where table_name='TEST2';
OWNER CONSTRAINT_NAME C TABLE_NAME
---------- -------------------- - ---------------
HR INDX_TEST2_ID U TEST2
HR@orcl150> select INDEX_NAME from user_indexes where table_name='TEST2';
INDEX_NAME
------------------------------
INDX_TEST2_ID
结论:表添加唯一键后,会自动生成相应索引.