表中某列被修改后触发器SQL例子

来源:互联网 发布:金山数据恢复大师破解 编辑:程序博客网 时间:2024/05/16 04:33
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>


CREATETABLE[TEST](
 [FID][int]IDENTITY(1,1)NOTNULL,
 [F1][int]NULL,
 [F2][int]NULL,
 [F3][int]NULL,
 CONSTRAINT[PK_TEST]PRIMARYKEY CLUSTERED
 (
  [FID]
 ) ON[PRIMARY]
)ON[PRIMARY]
GO


alterTRIGGERupdatetestON[dbo].[TEST]
FORINSERT,UPDATE,DELETE
AS
begin
 declare@F1 int,
  @FID int,
  @OldF1 int
 ifupdate(F1)
 begin
  select@OldF1=F1fromtestwhereFIDin(selectFIDfromINSERTED)
  select@FID=FID,@F1=F1fromINSERTED
  PRINT'fID='+convert(varchar(10),@FID)
  PRINT'OldF1='+convert(varchar(10),@OldF1)
  PRINT'F1='+convert(varchar(10),@F1)
 end
 
end

go

inserttest(f1,f2,f3)values(1,2,3)
go
select*fromtest
go
updatetestsetf1=11wherefid=1
go
--问题:不能获得修改前的值???

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击