Click here to Skip to main content
15,438,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two tables,user_info and follow with Primary-foregin relationship
like this:

create table user_info
(
ID bibigint gint identity(1,1) not null primary key
Name varchar(30),
.....
.....
)
 
create table follow
(
following bigint not null references user_info(ID) on delete cascade,
follower bigint not null references user_info(ID)  on delete cascade, 
CONSTRAINT uk_follow UNIQUE (following,follower)
)



Output:
First table is sucesfully created
but when i run to create follow table then error is thrown to me

Msg 1785, Level 16, State 0, Line 1<br />
Introducing FOREIGN KEY constraint 'FK__foll__follo__0AF29B96' on table 'follow' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.<br />
Msg 1750, Level 16, State 0, Line 1

Could not create constraint. See previous errors.

Note: But i want to implement on delete cascade in both columns, following and follower.

My actual requirement:
when any record is deleted from user_info table then that user should deleted from follow table based on ID column, that ID may be exist in following or follower column.

i want to delete all records of follow table when any id is related parent table is deleted from parent table
Posted
Updated 1-Feb-12 20:12pm
v3
Comments
Rajesh Anuhya 2-Feb-12 2:12am     CRLF
Edited code tags added --RA

1 solution

You can set your tables to allow a Delete Cascade.
Read more about this here[^].
 
Share this answer
 
Comments
Surendra Tarai 2-Feb-12 2:28am     CRLF
Hello abinav, can u tell what code will i write please for allow delete cascade ? and i do not want to use any trigger and store procedure.
Abhinav S 2-Feb-12 3:24am    
You need to change the table design using DDL queries.
Surendra Tarai 2-Feb-12 3:47am    
can u give example please ?

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