A
A
Andrew2019-09-01 13:44:56
SQL Server
Andrew, 2019-09-01 13:44:56

How to update data in two tables related by foreign key?

There are two tables connected by foreign keys, and you need to change them at the same time. How can I do that?
DB - MS SQL.
Tried wrapping updates in commits - didn't work

Begin Tran
Update...
Update...
Commit Tran

The base structure is something like this

[Работники]
int Id

[Заказы]
int Id

[Услуги]
int id

[Услуги в заказах]
int ЗаказId
int УслугаId

// Работники вынесены в отдельную таблицу потому, что разные работники могут делать разные услуги в одном заказе, а некоторые услуги могут быть без работников вообще
[Работники в услугах в заказах]
int ЗаказId
int УслугаId
int РаботникId

Need to update the last two tables

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
nApoBo3, 2019-09-01
@nApoBo3

MS SQL does not support delayed integrity checking. You can temporarily disable checks during a transaction and then enable them again. But it is better to rework the data structure or, alternatively, use a DBMS in which this feature exists.

K
Konstantin Tsvetkov, 2019-09-01
@tsklab

Delete the old one and add with new values.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question