1
create table test3
(
id int PRIMARY KEY,
id2 int
);

create unique index ndx_id2 on test3 (id2);

出于唯一索引的目的,所有NULL值都被认为与所有其他NULL值不同,因此是唯一的。这是对 SQL-92 标准的两种可能解释之一(标准中的语言是模棱两可的),也是 PostgreSQL、MySQL、Firebird 和 Oracle 遵循的解释。

Informix 和 Microsoft SQL Server 遵循该标准的其他解释。

INSERT INTO test3(id, id2) VALUES (1, null);
INSERT INTO test3(id, id2) VALUES (2, null);

第二次 INSERT 返回

不能将重复值插入唯一索引。[表名=test3,约束名=ndx_id2]

SQL CE 中的错误,但成功地将记录添加到另一个 DBMS,例如 Sqlite。

SQL CE中如何允许在具有唯一约束的字段中输入大量空值?

PS 这个问题解决了 Sql 2008 How to allow in the field with a unique constraint to enter a lot of null values in SQL Server but需要SQL CE的决定

4

1 回答 1

0

使用 SQL Server Compact,只允许唯一值,包括单个 NULL 值。

于 2013-05-16T11:14:46.800 回答