SQLServer 觸發器 數據庫停止數據備份。本站提示廣大學習愛好者:(SQLServer 觸發器 數據庫停止數據備份)文章只能為提供參考,不一定能成為您想要的結果。以下是SQLServer 觸發器 數據庫停止數據備份正文
create table test3(id int primary key not null
identity(1,1),uname varchar(20),uage int);
create table test3_bak(id int primary key not
null identity(1,1),bid int,uname varchar(20),
uage int,active char(1));
第二步,編寫備份用的觸發器,只要更新或許是拔出的時刻才觸發
alter trigger test3_bak_insert_update
on test3
for insert,update
as
declare @id int
declare @uname varchar(20)
declare @uage int
begin
select @id=id,@uname=uname,@uage=uage from inserted
if @id<>0
begin
update test3_bak set active='0' where bid=@id
insert into test3_bak(bid,uname,uage,active)
values(@id,@uname,@uage,'1')
end
end
第三步,測試數據:
insert into test3(uname,uage) values('FLB',20)
insert into test3(uname,uage) values('FLB1',21)
insert into test3(uname,uage) values('FLB2',22)
update test3 set uage=100 where id=27
delete from test3 where id=20
最初,你可本身采取上面辦法查詢跟蹤兩個表的數據變更:
select * from test3
select * from test3_bak