Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,
I have a question about Directed acyclic graphs. I am new to Microsoft SQL server coming from MySql. The reason why I am now using MS SQL is the need for nodle graphs in a relational database. I have been reading so much on this, I really need this to work. I have been trying this from http://techportal.ibuildings.com/2009/09/07/graphs-in-the-database-sql-meets-social-networks/ and I cannot get anything to work. I am just trying to create a few tables:

CREATE TABLE nodes (
 id INTEGER PRIMARY KEY,
 name VARCHAR(10) NOT NULL,
 feat1 CHAR(1), -- e.g., age
 feat2 CHAR(1)  -- e.g., school attended or company
);

CREATE TABLE edges (
 a INTEGER NOT NULL REFERENCES nodes(id) ON UPDATE CASCADE ON DELETE CASCADE,
 b INTEGER NOT NULL REFERENCES nodes(id) ON UPDATE CASCADE ON DELETE CASCADE,
 PRIMARY KEY (a, b)
);

CREATE INDEX a_idx ON edges (a);
CREATE INDEX b_idx ON edges (b);


The problem is I keep getting this error:
Msg 1785, Level 16, State 0, Line 8
Introducing FOREIGN KEY constraint 'FK__edges__b__628FA481' on table 'edges' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Msg 1750, Level 16, State 0, Line 8
Could not create constraint. See previous errors.


I am not sure what I am doing wrong, just need a little help.

Thanks
Golgi

What I have tried:


Posted
Updated 29-Dec-17 10:41am
v2

1 solution

have a look at this article, examples are at the bottom of the page

tsql index examples
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900