建立表时,为字段表示为identity
如:
  create table test(id identity(1,1) number not null,
     ...)

解决方案 »

  1.   

    同意 Michaelyfj(向五角星看齐) 的方法
    不过 id 的为 int 型
      

  2.   

    如果到了aaz下一个是什么?
      

  3.   

    to  jinfeng_wang(G-G-S,D-D-U):
    我就是想知道如何建立trigger
      

  4.   

    我觉得你要求的主键是char类型的,不能自动增一的。所以我同意jinfeng_wang(G-G-S,D-D-U) 的做法
    你在TRIGGER中要做的就是把identity计算成你所需要的值。
      

  5.   

    我试了一个:
    create trigger t1 on test
    for insert
    as 
    begin
    declare @a varchar(10)
    if exists (select 1 from test where id<>'999')
    begin
    select @a=max(id) from test
    set @a=(case when right(@a,1)<>'z' then left(@a,2)+char(ascii(right(@a,1))+1) 
              when substring(@a,2,1)<>'z'then left(@a,1)+char(ascii(substring(@a,2,1))+1)+'z' 
              when left(@a,1)<>'z' then char(ascii(left(@a,1))+1)+'zz' 
        else 'error' end)
    end
    else
    begin
    set @a='aaa'
    end
    update test set id=@a where id='999'
    end
    因为是主键,不能为空,要输入一个固值’999‘
    insert test values('999','2')
      

  6.   

    這問題用Default constraint最好了,寫一個Function,用來取最大值的,然後把這Function邦到主鍵上。