Answer the question
In order to leave comments, you need to log in
How to set multiple foreign keys for one table?
Good afternoon.
For the first time I encountered MSSQL database server.
With the help of two consecutive queries, I try to create two tables in it, the first one:
CREATE TABLE "item" (
"id" BIGINT IDENTITY(1,1) NOT NULL,
"name" NVARCHAR(255) NOT NULL,
CONSTRAINT "item_pk" PRIMARY KEY ("id"),
CONSTRAINT "unique_item_name" UNIQUE ("name")
)
CREATE TABLE "item_parent_child" (
"id" BIGINT IDENTITY(1,1) NOT NULL,
"parent_id" BIGINT NOT NULL,
"child_id" BIGINT NOT NULL,
CONSTRAINT "item_parent_child_pk" PRIMARY KEY ("id"),
CONSTRAINT "fk_item" FOREIGN KEY ("parent_id") REFERENCES "item" ("id") ON DELETE CASCADE,
CONSTRAINT "fk_child" FOREIGN KEY ("child_id") REFERENCES "item" ("id") ON DELETE CASCADE,
)
Introducing FOREIGN KEY constraint 'fk_child' on table 'item_parent_child' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question