克隆行并指向新行

时间:2013-11-10 10:49:17

标签: sql

我设法将table_source的一行克隆到table_temp, 并更新其字段f0

但是如何指向新插入的行?

我想将表table_source中的新插入ID插入f_id中的字段table2

INSERT into table_temp (f0, f1, f2)  
  select f0, f1, f2 from table_source   
  where . . .

UPDATE table_temp SET f0 =  'newValue'  

INSERT INTO table_source select * from table_temp  

UPDATE table2 SET f_id = ??? WHERE . . .      <- what id can I use here?

DELETE FROM table_temp 

1 个答案:

答案 0 :(得分:1)

Scope_Identity()返回当前范围内最后插入的行的标识符。另请参阅@@identity