select name,identity(int,1,1) as id into #table from table

解决方案 »

  1.   

    select name,identity(int,1,1) as id into #table from table
    select * from #table
      

  2.   

    --添加标识字段alter table table1 add id int identity(1,1)
      

  3.   

    zjcxc(邹建) ( ) 在自定义的函数里是不是不可以使用alter table 语句的?
    declare @r table(num int,name varchar(20),M_num int)
    insert @r select ....
    alter table @r add id int identity(1,1) '@r' 附近有语法错误。
      

  4.   

    quanyi(菜鸟) ( ) 自定义函数里不能使用临时表啊.
      

  5.   

    是的,在自定义的函数里不可以改变原有的表的结构和数据,以及不可以输出select的结果。好象是这样的。
      

  6.   

    --定义表的时候就定义进去嘛declare @r table(id int identity(1,1),num int,name varchar(20),M_num int)
      

  7.   

    alter table table1
       add (id int(1,1)