Note that there are some explanatory texts on larger screens.

plurals
  1. PO2 Cascading Deletes in Sql Server between 2 tables
    primarykey
    data
    text
    <p>Let's say I have 2 tables</p> <pre><code>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] </code></pre> <p>and </p> <pre><code>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] </code></pre> <p>The logic being that the transaction table requires 2 records from the people table, a buyer and a seller.</p> <p>What I am trying to do is implement cascading delete on both the BUYER_ID and SELLER_ID columns.</p> <p>However, I can add one (either) without a hitch, but if i try to add second one, when I go to save, I get an error message...</p> <pre><code>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. </code></pre> <p>Is there a way to do this without using triggers or are triggers the best way to do this</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload