gpt4 book ai didi

sql - 对表中的列强制执行唯一和多个NULL

转载 作者:行者123 更新时间:2023-12-02 07:47:20 25 4
gpt4 key购买 nike

如何在SQL Server中为表的列强制执行Unique值以及多个NULL?

最佳答案

this answer:

In SQL Server 2008, you can define a unique filtered index based on a predicate that excludes NULLs:

CREATE UNIQUE NONCLUSTERED INDEX idx_yourcolumn_notnull
ON YourTable(yourcolumn)
WHERE yourcolumn IS NOT NULL;

In earlier versions, you can resort to VIEWS with a NOT NULL predicate to enforce the constraint.

关于sql - 对表中的列强制执行唯一和多个NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6010508/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com