1. 插入数据前判断数据是否存在
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <Description,,> -- ============================================= alter TRIGGER CategoryExistTrigger ON ProductCategory instead of insert AS declare @categoryName varchar(50); BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for trigger here select @categoryName = CategoryName from inserted; if exists(select * from ProductCategory where CategoryName =@categoryName) begin print 'Category exists..' end; else begin insert into ProductCategory select * from inserted; end; END
2. 删除表中数据时需要先删除外键表的数据
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <Description,,> -- ============================================= alter TRIGGER DeleteOrderTrigger ON OrderHeader instead of delete AS declare @OrderId varchar(50); BEGIN SET NOCOUNT ON; select @OrderId = OrderId from deleted; delete from OrderLine where OrderId = @OrderId; END GO
标签:
Oracle,before触发器
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“SqlServer实现类似Oracle的before触发器示例”评论...
更新动态
20240524
20240524
- 《范玮琪15CD合集》[WAV+CUE][14.8G]
- 陈慧娴《BackToPriscilla30周年演唱会2CD》[WAV+CUE]
- 【乡村音乐】约翰尼·李《七月十三日、情感》2CD.2024[FLAC+CUE]
- 【发烧唱片】丹拿示范盘《为歌所吻》2014[FLAC+CUE]
- 颜人中.2022-查无此人【中视鸣达】【FLAC分轨】
- 苏慧伦.1996-LEMON.TREE【滚石】【WAV+CUE】
- 萧福德.1995-春秋大梦【飞碟】【WAV+CUE】
- 宇多田光-TheFirstLove【Hi-Res】FLAC
- KOKIA吉田亚纪子-2009-AKIKO∞KOKIA~balance~[FLAC]
- 中国人民解放军军乐团-《28首世界军乐精品大联奏(二)》[FLAC]
- 蓝岚《天空》人声与钢琴的对话[WAV分轨][464M]
- 群星《荒野彪客DTS》中国第一试音天碟 [DTS][440M]
- 贵族音乐《颂钵减压SPA 空灵疗心音乐精选》[320K/MP3][146.49MB]
- 群星.2005-男人魅【TVB.MUSIC】【WAV+CUE】
- 谢采妘.1999-旧情绵绵2CD【南方】【WAV+CUE】