Imagine table A like this:
create table A (
ID int primary key identity(1, 1),
Name varchar(20)
)
and table B:
create table B (
ID int primary key identity(1, 1),
A_ID int foreign key references A(ID)
Name varchar(20)
)
As I want to keep data even after deleting them, I want to have 2 tables called A1 and B1 in order to store an archive of old data like these:
create table A1 (
ID int primary key identity(1, 1),
Name varchar(20),
OldID int
)
create table B1 (
ID int primary key identity(1, 1),
A1_ID int foreign key references A1(ID),
Name varchar(20),
OldMasterID int
)
As you know whenever I want to send an A row I'll insert it and get the inserted ID using some tools like scope_identity() function in MS SQL Server. But how to transfer several rows and take the inserted ID in order to set as master's ID?
A solution is to use a loop like "while" and insert rows one by one. But I don't think about this solution a good performance way. Is there another way to do this?