主页 > 知识库 > 数据库 > SQL server >

sql server/sqlserver 2005/2000/2008的触发器来复制一条刚插入

来源: 作者: 发表于:2012-08-21 10:55  点击:
Create Trigger test_tri5 on test after insert as begin declare @id sysname, @tel sysname, @name sysname select @tel=ltrim(tel),@id=ltrim([id]),@name=ltrim([name]) from inserted; insert into test2(id,tel,[name]) values(@id,@tel,@name); end
 
 
 
Create Trigger test_tri5
on test
after insert
as
 
begin
declare @id sysname, @tel sysname, @name sysname
select @tel=ltrim(tel),@id=ltrim([id]),@name=ltrim([name]) from inserted;
insert into test2(id,tel,[name]) values(@id,@tel,@name);
end
 
这样,只要往test表插入一条记录,就回立马执行
 
insert into test2(id,tel,[name]) values(@id,@tel,@name);
往另外一张表中自动插入一条记录,并且获得了刚刚自动增加的id

    有帮助
    (0)
    0%
    没帮助
    (0)
    0%