标题: unique与primary key的区别?
酒杯与钢琴
LU新生
Rank: 1



UID 1927
精华 0
积分 7
帖子 13
活跃指数 0
LU金币 2006 个
LU金条 0 个
阅读权限 10
注册 2003-11-7
 
发表于 2003-11-24 12:22  资料  个人空间  短消息  加为好友 
这两种约束好象都能使TABLE的某一列的值或多列的组合值是唯一的,请问这两种约束有其它的区别??

顶部
larryh
超级版主
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17



LU爱心使者  
UID 133
精华 32
积分 4028
帖子 7422
活跃指数 293
LU金币 4771 个
LU金条 5409 个
阅读权限 251
注册 2003-9-26
 
发表于 2003-11-24 17:54  资料  个人空间  短消息  加为好友 
这是SYBASE文档中的一段:
unique – constrains the values in the indicated column or columns so
that no two rows can have the same non-null value. This
constraint creates a unique index that can be dropped only if the
constraint is dropped. You cannot use this option along with the
null option described above.
primary key – constrains the values in the indicated column or columns
so that no two rows can have the same value and so that the value
cannot be NULL. This constraint creates a unique index that can
be dropped only if the constraint is dropped.

看起来其区别是:
unique:允许NULL值
primary key:不允许NULL值

顶部
SunnyXu
技术专家
Rank: 14Rank: 14Rank: 14Rank: 14


UID 152
精华 2
积分 184
帖子 356
活跃指数 1
LU金币 5460 个
LU金条 0 个
阅读权限 200
注册 2003-9-27
 
发表于 2003-11-25 12:07  资料  个人空间  短消息  加为好友 
unique:列中可以有null值,一个表中可以有多个
primary key:列中不可以有null值,一个表中最多只能有一个,而且建议要有一个。

其它的基本一样





知识分为两种:会的与不会的。 会的就是容易的,不会的就是难的!
顶部
 



当前时区 GMT+8, 现在时间是 2008-12-2 13:21
乐悠LoveUnix论坛-京ICP备05005823号

Thanks to Discuz!  © 2001-2007    Power by LoveUnix.net
Processed in 0.051192 second(s), 6 queries , Gzip enabled

清除 Cookies - 联系我们 - 乐悠LoveUnix - Archiver