I have database tables TableA
and TableA_Stage
with same columns and I want to copy the records in TableA_Stage
to TableA
generating primary key based on maximum value in TableA
.
I tried this sql and it didn't work because same primary key value gets inserted :
insert into tableA(col_pk, col1, col2)
select (
select max(col_pk)+1
from tableA
),
col1, col2
from tableA_Stage
I am looking for sql statement to copy records