sql server T-SQL 插入临时表时使用自增长键

select identity(int,1,1) id ,* into #tmp from tablename

有一点要注意,不能将 tablename这个表中的自增长列一并插入到临时表中.

如果是SQLServer 2005 可以使用rownumber

select ROW_NUMBER() OVER (order by Id)as [index],a.id as Id into #temp from tablename

你可能感兴趣的:(SQL Server)