我試圖執行我通過Microsoft Visio的Forward Engineer Addin創建的數據庫腳本。SQL Server否匹配鍵錯誤消息
以下是我收到錯誤和錯誤信息被引用的代碼的部分:
錯誤1:
Msg 1776, Level 16, State 0, Line 12
There are no primary or candidate keys in the referenced table 'dbo.Account_BillingAccount' that match the referencing column list in the foreign key 'Account_BillingAccount_InvoiceDetail_FK1'.
Msg 1750, Level 16, State 0, Line 12
Could not create constraint. See previous errors.
代碼文獻1:
ALTER TABLE [dbo].[InvoiceDetail] WITH CHECK ADD CONSTRAINT [Account_BillingAccount_InvoiceDetail_FK1] FOREIGN KEY (
[BillingAccountNumber]
, [AccountNumber]
)
REFERENCES [dbo].[Account_BillingAccount] (
[BillingAccountNumber]
, [AccountNumber]
)
錯誤2:
Msg 1776, Level 16, State 0, Line 2
There are no primary or candidate keys in the referenced table 'dbo.ManagerContract' that match the referencing column list in the foreign key 'ManagerContract_RegionalCoordinators_FK1'.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.
代碼參考2:
ALTER TABLE [dbo].[RegionalCoordinators] WITH CHECK ADD CONSTRAINT [ManagerContract_RegionalCoordinators_FK1] FOREIGN KEY (
[AssociateID]
, [WritingNumber]
)
REFERENCES [dbo].[ManagerContract] (
[AssociateID]
, [WritingNumber]
)
什麼是消除上述誤差的最有效方法是什麼?
您必須在引用表中具有與列列表匹配的主鍵或唯一鍵。因此,在'ManagerContract'中,您需要'AssociateID,WritingNumber'和'Account_BillingAccount'上的唯一鍵,您需要'BillingAccountNumber,AccountNumber'。 –
添加此唯一密鑰的語法是什麼? – idealistikz