for example:
create table tbl
( [id] int identity(1,1) not null,
a varchar(10))

解决方案 »

  1.   

    楼上的是对的,还有一种方法
    是利用函数
    先创建函数
    create function getfun() 
    returns int 
    as 
    begin
    declare @n int
    select @n=isnull(max(id),0)+1 from ai
    return @n
    end
    create table ai (id int primary key default(dbo.getfun()),ii int)
      

  2.   

    我是说在sql server中如何将表的一个字段设置成自动增加的。因为我的表已经建立好了
      

  3.   

    可以吗?不行吧,如果可以那如果原来这个列里面的数据不附和规定怎么办。要不这样
    alter table xu002
      drop column a
    goalter table xu002
      add a int identity(1,1) primary key
      

  4.   

    alter table xu002 
    drop column a
    go
    alter table xu002
    add a int identity(1,1) not null,
    alter table xu002
    add constraint pk_a primary key(a)
      

  5.   

    加标识有数据的话
    ALTER TABLE 表 ADD 编号1 bigint identity(1,1) not null
    go
    SET IDENTITY_INSERT 表 ON
    go
    update 表 set 编号1=编号
    go
    SET IDENTITY_INSERT 表 OFF
    go
    ALTER TABLE 表 DROP COLUMN 编号 
    go
    exec sp_rename '表.编号1','编号'
    go
      

  6.   

    for example:
    create table tbl
    ( [id] int identity(1,1) not null,
    a varchar(10))
    或者在企业管理里面设计表标识下选是