nr: #1 dodano: 2016-12-29 01:12
If I have any questions about whether or not the order will be the same, I use an intermediate table binding the row_number() value to the pk. A simple example would be:
INSERT INTO #tmpPK
row_number() OVER(ORDER BY table1.pk ASC) as my_id
CREATE UNIQUE INDEX ix1 ON #tmpPK (pk) INCLUDE (my_id)
Then JOIN to this table while splitting the data:
SELECT t.my_id, ...
FROM table1 t1
INNER JOIN table2 t2
ON t1.pk = t2.fk
INNER JOIN #tmpPK t
ON t1.pk = t.pk
No matter what you do, that INNER JOIN from table1.pk to #tmpPK.pk ensures that the my_id value will be the same for the different PKs.
That said, unless there are rows missing from one table you are splitting to that might be added to the other table you are splitting to, I doubt you will have a problem.