久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

TSQL 多列唯一約束也允許多個空值

TSQL Multi Column Unique Constraint That Also Allows Multiple Nulls(TSQL 多列唯一約束也允許多個空值)
本文介紹了TSQL 多列唯一約束也允許多個空值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我目前正在從 MS Access 遷移到 SQL Server.Access 允許在唯一索引中有多個空值,而 SQL Server 則不允許......我一直在通過刪除 SQL Server 中的索引并添加過濾索引來處理遷移:

I am currently doing some migration from MS Access to SQL Server. Access allows multiple Nulls in unique indexes where as SQL Server does not... I've been handling the migration by removing the indexes in SQL Server and adding filtered indexes:

CREATE UNIQUE NONCLUSTERED INDEX idx_col1_notnull 
ON tblEmployee(col1) 
WHERE col1 IS NOT NULL;

我遇到的問題是我不確定如何實現復合或多列過濾"索引...或者這是否真的可行,因為我在研究中沒有發現任何例子.

The problem I am having is that I am not sure how to implement a composite or multi-column "filtered" indexes... or if this is really possible as I've found no examples in researching it.

我確實有一個想法,通過像這樣創建過濾索引來實現它:

I do have an idea to implement it by creating filtered indexes like so:

CREATE UNIQUE NONCLUSTERED INDEX idx_col1col2_notnull 
ON tblEmployee (col1, col2) 
WHERE col1 IS NOT NULL

然后添加第二個過濾索引:

And then adding a second filtered index:

CREATE UNIQUE NONCLUSTERED INDEX idx_col2col1_notnull 
ON tblEmployee (col1, col2) 
WHERE col2 IS NOT NULL

但我不確定這是否有效,更不用說是最好的方法了.非常感謝您提供正確方向的指導.

But I'm not sure if this would even work let alone be the best method. Guidance in the right direction would be greatly appreciated.

推薦答案

您可以添加以下索引以僅索引不可為空的列:

You can add the following index to index only non nullable columns:

create table tblEmployee(col1 int, col2 int)
go

create unique nonclustered index idx_col1col2_notnull ON tblEmployee(col1,col2) 
where col1 is not null and col2 is not null
go

--This Insert successeds
insert into tblEmployee values
(null, null),
(null, null),
(1, null),
(1, null),
(null, 2),
(null, 2)

--This Insert fails
insert into tblEmployee values
(3, 4),
(3, 4)

這篇關于TSQL 多列唯一約束也允許多個空值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 国产91丝袜在线播放 | 成人一区二区三区在线观看 | 亚洲一二三在线 | 精品日韩 | 欧美一区二区三区四区在线 | 精品欧美一区二区在线观看 | 日韩1区2区 | 免费看a | 中文字幕在线观看成人 | 美女天天操 | 日韩av成人在线观看 | 久久久精彩视频 | 国产三级电影网站 | 色婷婷婷婷色 | 91久久夜色精品国产网站 | 日本午夜网 | 久久久久国产 | 一区免费视频 | 国产一区二区三区免费 | 国产午夜精品久久久 | 国产91亚洲精品一区二区三区 | 日韩 国产 在线 | 偷拍自拍网站 | 欧美视频第二页 | 国产在线观看一区二区三区 | 国产精品久久久久久福利一牛影视 | 老熟女毛片| 国产成人av一区二区三区 | 九九九视频在线 | 久久成人免费视频 | 一区二区精品 | 超碰人人插 | 自拍偷拍亚洲欧美 | 伊人久久综合 | 欧美一级在线 | 午夜噜噜噜 | 99热视| 成人二区三区 | 精品国产一二三区 | 91成人精品| 国产视频91在线 |