主键都是uniqueidentifier字段
表A(ID主键,NAME)A表中插入一个(123,aaa)
uniqueidentifier的格式是123这样的?.

解决方案 »

  1.   

    create trigger A_insert
    on A
    for insert
    as
    insert B(ID,PpName) select ID, 'pp' from INSERTED
    go
      

  2.   

    --以另一个表的字段做默认值--创建测试表
    create table tb1(id int,name varchar(10))
    insert into tb1
    select 1,'张三'
    union all select 2,'李四'--测试表2,其中name是根据id字段的值从tb1中取得的.
    create table tb2(id int,name varchar(10),sex int)
    go--创建处理的触发器
    create trigger t_insert on tb2
    after insert
    as
    update tb2 set name=b.name
    from tb2 a
    join tb1 b on a.id=b.id
    join inserted  c on a.id=c.id
    go--插入数据测试
    insert into tb2(id,sex)
    select 1,10
    union all select 1,20
    union all select 2,20--显示结果
    select * from tb2go
    --删除测试环境
    drop table tb1,tb2