关系型数据库如果我定义了2列为主键,其中一列可以为空么?

来源:百度知道 编辑:UC知道 时间:2024/05/30 09:07:09
假如我定义field a,b,联合为主键,那么其中一列,比如说b能为空么?

自己测试下不就知道了??

create table test123(
id int,
id2 int,
primary key(id,id2)
)

insert into test123 (id) values(23)

消息 515,级别 16,状态 2,第 2 行
不能将值 NULL 插入列 'id2',表 'ztx.dbo.test123';列不允许有空值。INSERT 失败。
语句已终止。

insert into test123 (id,id2) values(23,34)
(1 行受影响)

事实证明:主键的值不能为空!

可以啊。你试一下往里面插入数据就是啦。