我試圖到SQL Server 2008,我收到以下錯誤上增加一個檢查約束,當我運行這段代碼:alter命令與檢查約束髮生衝突(但沒有行違反約束)
alter table db.dbo.myTable add constraint
noWWWifProgramIsKnown check
(dbo.checkcountuniversalservice(A, B,
C)=0 and program='WWW')
引發錯誤:
The ALTER TABLE statement conflicted with the CHECK constraint "noWWWifProgramIsKnown". The conflict occurred in database "db", table "dbo.tableuniversalservice".
Marc_s'的SO回答說,這很可能是b/C的一些行違反約束: The ALTER TABLE statement conflicted
Howeve r,沒有行違反約束,因爲這返回0:
select COUNT(*) from db.dbo.tableuniversalservice
where
(dbo.checkcountuniversalservice(A, B, C)=0
and
program='WWW'
)
我在想什麼?
@marc_s什麼想法? – bernie2436
與表名一樣,您的'SELECT'語句看起來與您想要的相反:您查詢的是符合'CHECK'條件的行數,結果爲零。因此,表中沒有行,或者它們都與'CHECK'約束相沖突。你可能打算輸入'SELECT ... WHERE NOT(...)'? – Pondlife