insert into a(name,storeid) select name ,XXX=row_number() over(order by name) from b
用游標新增,或在新增前 在alter table b add ID int identity--新增標識列
SELECT name,IDENTITY(1,1)AS ID INTO TB FROM Binsert into a(name,storeid) select name ,ID from TB DROP TABLE TB
if object_id('tempdb..#t') is not null drop table #tSELECT IDENTITY(int,1,1) as XXXX ,name INTO #t FROM bINSERT INTO a SELECT name,XXXX FROM #t ORDER BY XXXX
select name ,XXX=row_number() over(order by name)
from b
SELECT name,IDENTITY(1,1)AS ID INTO TB FROM Binsert into a(name,storeid)
select name ,ID from TB DROP TABLE TB
if object_id('tempdb..#t') is not null
drop table #tSELECT IDENTITY(int,1,1) as XXXX ,name INTO #t FROM bINSERT INTO a SELECT name,XXXX FROM #t ORDER BY XXXX