国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > SQL Server > 正文

SqlServer實現類似Oracle的before觸發器示例

2020-07-25 12:56:57
字體:
來源:轉載
供稿:網友

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
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临泽县| 漠河县| 丁青县| 慈利县| 濮阳县| 外汇| 呈贡县| 西乌珠穆沁旗| 银川市| 拉萨市| 阳曲县| 通化市| 大姚县| 曲阳县| 长汀县| 宿迁市| 东港市| 贵州省| 进贤县| 象山县| 台南县| 沛县| 荔浦县| 明水县| 抚州市| 娄底市| 屯留县| 包头市| 唐河县| 黔江区| 来安县| 余江县| 遂平县| 泰和县| 平遥县| 衡南县| 柳州市| 福贡县| 龙州县| 电白县| 永州市|