Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Error in adding 'ON DELETE CASCADE'

$
0
0

Hello,

I am getting an error while running a query,

I have two tables Parent and Child. In both tables I have columns named Name, Place and State. I know its not a good practice to have that, but for time being I cant change that.

So I have added 'Unique constraint' for 3 columns (Name, Place and State) in parent table using,

Text
 ALTER TABLE parent ADD  UNIQUE(column) 

and created foreign key in Child table using,

ALTER TABLE child ADD

FOREIGN KEY (column) REFERENCES parent(column);


While adding 'ON DELETE CASCADE' to child table I am getting error, that

"There are no primary or candidate keys in the referenced table"

Is it possible to set ''ON DELETE CASCADE" without adding primary key in the parent table ?

Also how to add "ON DELETE CASCADE" for some foreign keys ? In my case I have 3 foreign keys ( Name, Place and State)....


Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>