Yohan Wijayanto
Yohan Wijayanto

Reputation: 25

SQL Server AFTER UPDATE trigger to update another table

I have tables master_product and transactions.

If I change productID in the master_product table, I want to update the ProductID column in the transactions table.

I want to use a trigger, but I don't know how to write it. Can you please help me write the trigger?

Thank you.

Upvotes: 0

Views: 287

Answers (1)

Edgard
Edgard

Reputation: 71

It may be easier to change your foreign key constraint and add "ON UPDATE CASCADE" ?

SQL Server will manage everything.

alter table Categories drop constraint your_constraint_name
go
alter table Categories add constraint your_constraint_name
foreign key (productID) references master_product (productID) on update cascade on delete no action

Upvotes: 1

Related Questions