1
我有兩個表,我希望HEDE2列作爲HEDE表的FOREIGN KEY REFERENCES。對於創建第二個表,它將不允許,因爲它有警告:SQL Server:multi CASCADE操作
在列級別FOREIGN KEY約束中指定了多個鍵'HEDE2'。
但是,當我試圖ALTER TABLE HEDE2
FOREIGN KEY它允許我這樣做。有誰知道爲什麼會發生這種情況。這是一個錯誤?
CREATE TABLE cascde.HEDE
(
HedeID INT,
HedeID2 INT,
HedeID3 INT
CONSTRAINT PK_HEDE
PRIMARY KEY (HedeID, HedeID2, HedeID3)
)
GO
CREATE TABLE HEDE2
(
Hede2ID INT PRIMARY KEY IDENTITY(1,1) ,
HedeID INT,
HedeID2 INT,
HedeID3 INT
CONSTRAINT FK_HedeID
FOREIGN KEY (HedeID, Hede2ID, HedeID3)
REFERENCES cascde.HEDE (HedeID, HedeID2, HedeID3)
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
爲外鍵更改表HEDE 2。這讓我這樣做:
ALTER TABLE cascde.HEDE2
ADD CONSTRAINT FK_HEDE
FOREIGN KEY(HedeID, HedeID2, HedeID3)
REFERENCES cascde.HEDE (HedeID, HedeID2, HedeID3)
ON UPDATE NO ACTION
ON DELETE NO ACTION
GO
感謝@cynic尋求幫助。有效。 – cunay