Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Server ON DELETE CASCADE Error
    primarykey
    data
    text
    <p>I'm designing a database schema, and I'm stuck on one part. Below is a simplified version of my schema. Could someone please explain why the following SQL:</p> <pre><code>CREATE TABLE Users ( UserID INT NOT NULL PRIMARY KEY, FName VARCHAR(64) NOT NULL, LName VARCHAR(64) NOT NULL, UName VARCHAR(64) NOT NULL UNIQUE, PWord CHAR(32) NOT NULL, Role VARCHAR(13) NOT NULL ); ... CREATE TABLE Sale ( SaleID INT NOT NULL PRIMARY KEY, Book INT NOT NULL REFERENCES Books(BookID) ON DELETE NO ACTION, Merchant INT NOT NULL REFERENCES Users(UserID) ON DELETE CASCADE, Upload DATETIME NOT NULL, Sold BIT NOT NULL, Price DECIMAL(10, 2) NOT NULL, Condition VARCHAR(9) NOT NULL, Written BIT NOT NULL, Comments VARCHAR(8000) NULL ); ... CREATE TABLE Purchases ( PurchaseID INT NOT NULL PRIMARY KEY, Buyer INT NOT NULL REFERENCES Users(UserID) ON DELETE CASCADE, Merchant INT NOT NULL REFERENCES Users(UserID) ON DELETE NO ACTION, Sale INT NOT NULL REFERENCES Sale(SaleID) ON DELETE CASCADE UNIQUE, Time DATETIME NOT NULL ); </code></pre> <p>... results in this error, and how I can overcome it:</p> <pre><code>Msg 1785, Level 16, State 0, Line 38 Introducing FOREIGN KEY constraint 'FK__Purchases__Sale__25869641' on table 'Purchases' 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>I would like to keep the <code>ON DELETE CASCADE</code> for the <code>Purchases.Sale</code> attribute, if possible.</p> <p>Thank you for your time.</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.
 

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