各位大虾,我想做这样一个操作,不知可行否
    
    当我后台往SQL Server里面插入数据的时候,比如我这一次往数据库里面插的有2条数据,那这个字段里面的值就为:一个6位数的自然序号 为:000001  当我第二次往数据库里面一次性插入3条数据数据时。对应这三条数据里面的字段为:000002
依次。。    这样能实现吗?
    如果能,各位大虾给个方法,万分感激

解决方案 »

  1.   

    做个自增列。create table tb(id int identity(1,1),right(1000000+id,6) as code)
      

  2.   

    这个可以用两张表实现,第一个表id字段为自增长,关联第二张表的id字段就可以了在存储过程中,先插入表1,再插入表2
      

  3.   

    http://blog.csdn.net/roy_88/article/details/1424370參照例子
      

  4.   

    create table tb(
    id int identity,
    ida int,
    scode varchar(10),
    data int
    )create trigger tb_insert_y
    on tb
    for insert
    as 
    begin
    declare @ida int
    select  @ida=isnull(max(ida),0) from tb t
    where not exists(select 1 from inserted where t.id=id)
    update tb
    set ida=@ida+1,scode=right(100000+@ida+1,5)
    from tb t,inserted i
    where t.id=i.id
    end insert into tb(data)select id from tb_tmpselect *  from tb