触发器练一练

alter trigger studentchufa_delete
on studentchufa
instead of delete
as
    declare @count int
    select @count=count(*)from deleted
    declare @i int
    set @i=0
    while @i<@count
    begin
    declare @code bigint
    declare @name varchar(50)
    declare @phone bigint
    declare @addresss varchar(50)
    select top 1 @code=code,@name=name,@phone=phone,@addresss=addresss from deleted 
    where code not in(select top(@i) code from deleted)
    
    insert into studentchufabak values(@code,@name,@phone,@addresss)
    delete from studentchufa where @code=code
    
    set @i=@i+1
    end
go

delete from studentchufa where code=1223061308


select *from studentchufabak

 

posted @ 2015-04-29 22:48  XCml  阅读(122)  评论(0编辑  收藏  举报