我想要一个存储过程,它将行插入到一个表中(从另一个表的选择查询中检索),并且对于每个新插入的行获取它的标识并使用标识更新原始表
伪代码-
records = select id,city,state,country from USER where name=@name
for each record in records // for each rows selected
insert into LOCATION(city,state,country) values(@record.city,@record.state,@record.country); //inserts a value into LOCATION table
@id = SCOPE_IDENTITY(); // gets the identity of the newly inserted row
update USER set LocationId=@id where Id=@record.id //updates the new id back to old table's column
end
这是一个数据迁移任务,我们希望将 LOCATION 从 USER 表中分离出来
提前感谢您为此线程付出的时间和精力。