现数据库中有一张表,如test有三个字段,如A1,A2,A3,已知A1为标识种子,自动增长的。现在想实现如下功能:
用INSERT 插入一条新的记录时,想实现A2的值与A1的值相同。用存储过程或T-SQL语句都可以,请问该如何做呀

解决方案 »

  1.   

    create trigger t_test on test
    for insert
    as
    begin
        update test
        set
            A2=A1
        from 
            inserted
        where
            test.A1=inserted.A1
    end
    go
      

  2.   

    create table test(
    id int identity(1,1),
    id2 as id,
    id3 int
    )insert test(id3) 
    select 3
    union all select 4select * from test
      

  3.   

    设计表--〉选中A2列---〉公式那填上A1如果采用这种办法,那么是否是 insert 语句中,不用关A2 的值了,让sql server自动计算昵
      

  4.   

    设计表--〉选中A2列---〉公式那填上A1如果采用这种办法,那么是否是 insert 语句中,不用关A2 的值了,让sql server自动计算昵这样就不用管a2了,你插入保存A2会自动取的a1值