如何自动生成一个字段,自动生成序号阿?

解决方案 »

  1.   

    select 
     identity(int,1,1) AS Sequence,
     col1
    into
      table2
    from table1
      

  2.   

    Create table tb(id int identity(1,1),a varchar(10), b varchar(10))
    insert into tb select 'a','b'
    union all select 'c','d'select * from tbid 为自增.
      

  3.   

    --查询生成序号:
    select ROW_NUMBER() over( order by 排序字段),* from 表
      

  4.   

    declare @a table(a int identity(1,1),b nvarchar(100))
    insert into @a select a union all
    select b union all
    select c union all
    select d
    select * from @a1 e
    2 b
    3 c
    4 d(所影响的行数为 4 行)
    (所影响的行数为 4 行)
      

  5.   

    alter table tb
    add [id] int identity(1,1)
      

  6.   

    alter table tb
    add [id] bigint identity(1,1) not null