当我们直接用
select top 10 [ID] ,Identity(int,1,1) as rowIndex,Title,hits into #tmp from _Table
select * from #tmp
drop table #tmp
时,会报错:无法使用 SELECT INTO 语句向表 #tmp 中添加标识列 ID.因为原来的表_Table中已经存在标识列ID.
如果用
set nocount on
select top 10 [ID] ,Identity(int,1,1) as rowIndex,Title,hits into #tmp from(Select TOP 100 Percent * from _Table
order by hits desc) b
select * from #tmp
drop table #tmp
是却不会报错,这个我也弄不清楚.为是什么?