SQL> create table t1(id1 char(2),id2 char(2),id3 char(2));
Table created.
SQL> desc t1
Name Null? Type
----------------------------------------- -------- ----------------------------
ID1 CHAR(2)
ID2 CHAR(2)
ID3 CHAR(2)
SQL> insert into t1 values('a',null,'a');
1 row created.
SQL> commit;
Commit complete.
SQL> select * from t1;
ID ID ID
-- -- --
a a
SQL> alter table t1
add constraint PK_EMP primary key (id1,id2,id3); 2
add constraint PK_EMP primary key (id1,id2,id3)
*
ERROR at line 2:
ORA-01449: column contains NULL values; cannot alter to NOT NULL
SQL> create unique index t1_idx1 on t
Primary key and Unique index
最新推荐文章于 2023-07-15 13:22:49 发布
本文通过创建和操作SQL表`t1`,探讨了主键(primary key)与唯一索引(unique index)的区别。尝试将(id1, id2, id3)设为主键时遇到错误,因为主键不允许包含NULL值,而创建基于同样列的唯一索引成功。当尝试插入重复的记录时,唯一索引阻止了这一操作,违反了唯一性约束。"
137968264,7337247,马尔可夫链详解:概念、原理与应用,"['计算科学', '神经计算', '深度学习', '神经网络', '大数据']
摘要由CSDN通过智能技术生成