primary key 和unique key 的区别
一般情况下,primary key 和unique key都唯一地标识表的一行记录,那这两者有什么区别呢?
我现在发现的区别是primary key可以不可以插入空值,unique key则可以。举个例子:
create table test(id number unique);
insert into test values(null);
insert into test values(null);
insert into test values(null);
可以插入,这样id 不是不唯一了吗?不知道大家有什么看法?
然后select * from test where id=null,没记录。
如果是select * from test where id is null 就查询到三行记录,看来=null与 is null对于oracle来说是不一样的.
对于primary key呢,则不能插入值,如
create table test1 (id number primary key);
insert into test1 values(null);
则会报错。