I have a T1
table where I have ID
.
I have a T2
table where it gets the ID_T1
( Foreign Key ) of T1
.
I have a T3
table where it gets the ID_T1
( Foreign Key ) of the T1
and the ID_T2
( Foreign Key .
In the T2
table, the IDs of the T3
are right, however, the T1
I created after these registers have been inserted, that is, they are with the records of the T3
to ID_T2
column. Is there any way I can do some NULL
in UPDATE
, passing all T3
IDs in the correct way?
Here is the code I'm trying to do:
UPDATE T3
SET T3.ID_T2 = (
SELECT T2.ID
FROM T2
INNER JOIN T3 ON T2.ID_T1 = T3.ID_T1
)
WHERE T3.ID_T1 = (
SELECT T1.ID
FROM T1
INNER JOIN T3 ON T3.ID_T1 = T1.ID
INNER JOIN T2 ON T2.ID_T1 = T3.ID_T1
)
In SQL Server 2008.