Hi, I am new.
I have two table like this

create table1(
ID VARCHAR(10),
CONSTRAINT PKeyt1 PRIMARY KEY (ID)
)

create table2(
ID1 VARCHAR(10),
ID2 VARCHAR(10)
)

I want to add foreign key to table2 which ID1 and ID2 is different but referenced same column ID and ON UPDATE CASCADE. I tried every way which I now but I get this error


Msg 1785, Level 16, State 0, Line 2
Introducing FOREIGN KEY constraint 'blabla' on table 'blabla' 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 2
Could not create constraint. See previous errors.


How can I do this or can sql do this :)) thanks for reply...

No it isnt help to me because I want to add ON UPDATE CASCADE foreach key but in this link used ON UPDATE CASCADE just for one key... Can we do foreach key in mssql?

You can use triggers as said in the KB.

I do that ON UPDATE NO ACTION ON DELETE NO ACTION but I am very bad in trigger Can anybody give simple example for trigger?

Thanks for reply I do trigger bu I get error when I update row like this:

The UPDATE statement conflicted with the REFERENCE constraint "blabla". The conflict occurred in database "blabla", table "blabla".

I think my wrong in describing foreign key. I did it like this

ALTER TABLE blabla ADD CONSTRAINT blabla FOREIGN KEY (blabla,blabla) REFERENCES blabla(blabla,blabla) ON UPDATE NO ACTION ON DELETE NO ACTION

Can anybody have an idea?

blabla blabla blabla I don't understand anything.
Logically you need to update the two columns of table2 when the primary key of table1 changes?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.