用select ... into ... from ... 语句不就可以了?

解决方案 »

  1.   

    你没有看清楚题目,就这样去不掉Identity属性。
      

  2.   

    select * into #temp1 from A order by UserID
    go
    alter table #temp1 add UserID1 int
    go
    update #temp1 set UserID1 = UserID
    go
    alter table #temp1 drop column UserID
    go
    use tempdb
    go
    exec sp_rename '#temp1.UserID1','UserID','column'
    go
    use yourdb
    go
    select identity(int,1,1) ID,* into #B from #temp1
    go
    select * from #B
      

  3.   

    你的意思是不是要在临时表中得到一个连续的 ID, 并且不希望该临时表中有Identity属性, 可这样:select identity(int,1,1) as ID, UserID,UserName,UserValue
        into #TA
        from 表Aselect ID*1 as ID, UserID,UserName,UserValue
        into #B
        from #TA要两步, 第二步的ID*1用来去掉Identity属性.是你需要的吗?
      

  4.   

    好!
    在4no的基礎上擴展一下:select UserID*1 UserID,UserName,UserValue into #A from A order by UserID;
    go
    select identity(int,1,1) ID,* into #B from #A;
    go
      

  5.   

    select UserID*1 UserID,UserName,UserValue into #A from A order by 1;
    go
    select identity(int,1,1) ID,* into #B from #A;
    go