547是用於任何違反約束,不只是外鍵的錯誤代碼,例如:
create table T (
ID int not null,
constraint CK_Not1 CHECK (ID != 1)
)
go
insert into T (ID) values (2)
go
update T set ID = 1
(1 row(s) affected)
Msg 547, Level 16, State 0, Line 1
The UPDATE statement conflicted with the CHECK constraint "CK_Not1". The conflict occurred in database "Flange", table "dbo.T", column 'ID'.
The statement has been terminated.
話雖這麼說,我想不出任何其他類型的約束,而不是外鍵,可能會違反
DELETE
聲明。
(帽尖到@onedaywhen)
如果您在sys.messages
看,你會看到547必須對違反約束:
select text from sys.messages where message_id=547 and language_id=1033
The %ls statement conflicted with the %ls constraint "%.*ls". The conflict occurred in database "%.*ls", table "%.*ls"%ls%.*ls%ls.
「我想不出任何其他類型的約束,除了外鍵,可能會被DELETE語句違反」 - 請參閱我的答案。 – onedaywhen
你說違約約束,但2627呢?這是一個獨特的約束違規是不是?儘管如此,這並不會違反「DELETE」。我認爲你的意思是任何_check_約束違規。 – enashnash