语法
代码如下 | 复制代码 |
CREATE or REPLACE TRIGGER trigger_name DECLARE BEGIN EXCEPTION END; |
看个实例
For Example
创建一个数据表,结构如下
代码如下 | 复制代码 |
CREATE TABLE orders |
然后,我们可以创建一个AFTER INSERT触发器如下:
代码如下 | 复制代码 |
CREATE OR REPLACE TRIGGER orders_after_insert |
上面不知道大家看懂了没,我把自己写的整出来
代码如下 | 复制代码 |
set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO ALTER trigger [dbo].[toplist] on [dbo].[TB_TRADE_0170] AFTER insert,update as begin D eclare @ydlx varchar(50), @company [varchar](200), @code [varchar](6), @stock_name [varchar](20), @date [varchar](10), @daily [float], –@price [float], @inje [float], @outje [float], @je [float], @gpje [float], @injeb [float], @outjeb [float], –@gpjeb [float], @startDate varchar(10) if EXISTS(select * from inserted) select @ydlx = f002v_0170 ,@company = f004v_0170 ,@code = ob_seccode_0170 ,@stock_name = ob_secname_0170 ,@date = convert(varchar(10), ob_tradedate_0170, 120) ,@inje = f005n_0170/10000 ,@outje = f006n_0170/10000 ,@je = @inje+@outje from inserted where ob_isvalid_0170=1 else if exists(select * from new) select @ydlx = f002v_0170 ,@company = f004v_0170 ,@code = ob_seccode_0170 ,@stock_name = ob_secname_0170 ,@date = convert(varchar(10), ob_tradedate_0170, 120) ,@inje = f005n_0170/10000 ,@outje = f006n_0170/10000 ,@je = @inje+@outje from new where ob_isvalid_0170=1 select @daily = f015n_0160, @gpje = f016n_0160/10000, @injeb = case when f016n_0160 is not null and f016n_0160>0.001 then @inje/f016n_0160*100 else 0.0 end, @outjeb = case when f016n_0160 is not null and f016n_0160>0.001 then @outje/f016n_0160*100 else 0.0 end from tb_trade_0160 where tb_trade_0160.ob_seccode_0160 = @code and convert(varchar(10), ob_tradedate_0160, 120)=@date and ob_isvalid_0160=1 insert into [tccj_toplist] ([ydlx],[company] ,[code],[stock_name] ,[date],[daily],[inje],[outje],[gpje],[injeb],[outjeb] ) values( @ydlx,@company,@code,@stock_name,@date, @daily ,@inje,@outje,@gpje,@injeb,@outjeb) end |
永劫无间手游测试服 安卓版v1.0.262342
下载永劫无间手游台服 安卓版v1.0.262342
下载永劫无间手游国际服 安卓版v1.0.262342
下载永劫无间手游豌豆荚版 安卓版v1.0.262342
下载曼德拉男孩 最新版v2025.1.1
曼德拉男孩是一款专为女性玩家准备的治愈类恋爱游戏,在这里玩家
游戏开发者无限金币版 最新版v1.0.16
游戏开发者内置菜单版是一款非常好玩的模拟经营类手游,内部有功
没有中间商赚差价内购版 最新版v23.7.3
没有中间商赚差价免广告是一款非常好玩的模拟经营类手游,无需看
我的世界某不科学的空岛下载mcbbs 最新版v隔壁老王
我的世界某不科学的空岛整合包是一款像素风格的模拟沙盒游戏,该
洗衣店模拟器无限钞票免广告版 v2.2.2
洗衣店模拟器无限钞票版是一款模拟经营类手游,玩家们将在游戏中