比方說,我有2個表2級聯刪除在SQL中2個表
CREATE TABLE [dbo].[People](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Nom] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_People] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
和
CREATE TABLE [dbo].[Transactions](
[ID] [int] IDENTITY(1,1) NOT NULL,
[BUYER_ID] [int] NOT NULL,
[SELLER_ID] [int] NOT NULL,
[DateTransaction] [datetime] NOT NULL,
CONSTRAINT [PK_Transactions] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
的邏輯是,交易表,需要從人表2分的記錄,買家和一個賣家。
我想要做的是在BUYER_ID和SELLER_ID列上實現級聯刪除。
不過,我可以添加一個(或)順利,但如果我嘗試添加第二個,當我去救人,我得到一個錯誤信息......
Unable to create relationship 'FK_Transactions_Buyer'.
Introducing FOREIGN KEY constraint 'FK_Transactions_Buyer' on table 'Transactions' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
是否有如何在不使用觸發器的情況下執行此操作,或者觸發器是執行此操作的最佳方法
我添加了約束需要不同的ID在同一交易買方和賣方。這並不能解決問題。 – SerenityNow