您好,我想复制一张表中的一行数据,并将其主键内容换成其他数据,然后添加进这张表,请问SQL该怎么写?

2025-03-06 22:44:47
推荐回答(2个)
回答1:

select * into #temp from tab where xxx=xxx;
update #temp set 主键=xxx where xxx=xxxx;(如果只有一条那么就不用where了)
insert into tab select * from #temp

回答2:

下面语句挑出主键是123的数据,然后插入回原来的表,主键换成1234.

insert into tableName(pk, col1, col2...)
select 1234, col1, col2...
from tableName where pk = 123