Rosenberg
Rosenberg

Reputation: 2454

How to update same columns on different tables at the same time?

I have Table-A with a column called serial_number, and Table-B has the same column.

Update a single table is not possible to their linkage, upon attempt though, this is the error:

The UPDATE statement conflicted with the FOREIGN KEY constraint "L_231". The conflict occurred in database "Main", table "dbo.Products". The statement has been terminated.

I know how I can delete the field in both in case I need to, I just don't know how to update it simultaneously.

Thanks.

Upvotes: 1

Views: 253

Answers (3)

jack.mike.info
jack.mike.info

Reputation: 128

Hello

Good question but ????

one Method is Update trigger

you update in same time on different table

Upvotes: 0

RacerX
RacerX

Reputation: 2784

this is a BAD design. if this isn't a "one time thing" to fix an issue, but part of your applicaion, you need a redesign.

You shouldn't update keys, use a surrogate key (like an identity) instead and then store the serial_number as a plain data column (which can be easily changed).

Upvotes: 2

Andrew Lazarus
Andrew Lazarus

Reputation: 19340

You should be able to set the constraint as ON UPDATE CASCADE.

Upvotes: 1

Related Questions