当前位置:网站首页>Gbase 8C trigger (III)
Gbase 8C trigger (III)
2022-07-03 02:22:00 【Dazhuang twelve】
A trigger definition can also specify a Boolean WHEN Conditions , It will be tested to see if the trigger should be triggered . In row level triggers ,WHEN The condition can check the old column value of the row and / Or new column value ( Statement level triggers can also have WHEN Conditions , But this feature is not very useful for them ). In a BEFORE Trigger ,WHEN The condition is only calculated before the function is or will be executed , Therefore use WHEN There is no essential difference between the condition and the same condition tested at the beginning of the trigger function . however , In a AFTER Trigger ,WHEN The condition is only calculated after the row update occurs , And it determines whether an event is queued at the end of the statement to trigger the trigger . So when a AFTER Trigger WHEN Do not return to true time , There is no need to queue an event at the end of the statement , There is no need to take out the line again . If the trigger only triggers for a few rows , This can significantly speed up the modification of many line statements .INSTEAD OF Trigger does not support WHEN Conditions .
Usually , Row level BEFORE It is used to check or modify the data to be inserted or updated . for example , One BEFORE Triggers can be used to insert the current time into a timestamp In the column , Or check whether the two elements of the row are consistent . Row level AFTER Triggers are mostly used to propagate updates to other tables , Or check the consistency of other tables . The reason for this division of work is , One AFTER The trigger can be sure that it sees the final value of the row , And one BEFORE Triggers cannot , Because there may be others BEFORE Trigger triggers after it . If you don't know, let a trigger be BEFORE or AFTER, be BEFORE Form is more effective , Because the information about this operation does not need to be saved until the end of the statement .
If a trigger function executes SQL command , Then these commands may trigger the trigger again . This is the so-called cascade trigger . There is no direct limit on the number of cascaded layers . Cascading may lead to recursive calls to the same trigger . for example , One INSERT The trigger may execute a command to insert an extra row into the same table , This leads to INSERT The trigger is triggered again . So in this case , Trigger programmers should be responsible for avoiding infinite recursion .
When defining a trigger , You can specify parameters for it . The purpose of including parameters in the trigger definition is to allow different triggers with similar requirements to call the same function . for example , There may be a general trigger function , It requires two column names as parameters , One puts the current user and the other puts the current timestamp . When written correctly , This trigger function should be independent of the table it triggers . Therefore, the same function can be used on any table with appropriate columns INSERT event , One of the purposes of this is to automatically track the creation of records in a transaction table . If defined as a UPDATE trigger , It can also be used to track the latest update events .
Each programming language that supports triggers has its own way to make trigger input data available to trigger functions . This input data includes the type of trigger event ( Such as INSERT or UPDATE) And listed in CREATE TRIGGER Any parameter in . For a row level trigger , Input data also includes for INSERT and UPDATE Trigger NEW That's ok , and / Or for UPDATE and DELETE Trigger OLD That's ok .
default , Statement level triggers have no way to check a single row modified by a statement . however AFTER STATEMENT Triggers can request the creation of transformation tables to make the affected rowsets available to triggers .AFTER ROW Triggers can also request conversion tables , So that they can see all the changes in the table and the changes in the single row they are currently triggering . The method of checking the transformation table again depends on the programming language being used , But the typical method is
边栏推荐
- RestCloud ETL 跨库数据聚合运算
- 微服务组件Sentinel (Hystrix)详细分析
- Cancellation of collaboration in kotlin, side effects of cancellation and overtime tasks
- The use of Flink CDC mongodb and the implementation of Flink SQL parsing complex nested JSON data in monggo
- MySQL learning 03
- SPI机制
- Deep learning notes (constantly updating...)
- GBase 8c触发器(二)
- CFdiv2-Fixed Point Guessing-(区间答案二分)
- Javescript 0.1 + 0.2 = = 0.3 problem
猜你喜欢
MySQL learning 03
Use go language to realize try{}catch{}finally
[shutter] bottom navigation bar implementation (bottomnavigationbar bottom navigation bar | bottomnavigationbaritem navigation bar entry | pageview)
《上市风云》荐书——唯勇气最可贵
详细些介绍如何通过MQTT协议和华为云物联网进行通信
4. 类和对象
awk从入门到入土(0)awk概述
Wechat applet Development Tool Post net:: Err Proxy Connexion Problèmes d'agent défectueux
easyPOI
The data in servlet is transferred to JSP page, and the problem cannot be displayed using El expression ${}
随机推荐
力扣(LeetCode)183. 从不订购的客户(2022.07.02)
Gbase 8C system table PG_ database
Packing and unpacking of JS
【ROS进阶篇】第六讲 ROS中的录制与回放(rosbag)
8 free, HD, copyright free video material download websites are recommended
Codeforces Round #418 (Div. 2) D. An overnight dance in discotheque
Gbase 8C system table PG_ collation
How to find summer technical internship in junior year? Are you looking for a large company or a small company for technical internship?
require. context
RestCloud ETL 跨库数据聚合运算
Cancellation of collaboration in kotlin, side effects of cancellation and overtime tasks
Introduce in detail how to communicate with Huawei cloud IOT through mqtt protocol
Restcloud ETL cross database data aggregation operation
创建+注册 子应用_定义路由,全局路由与子路由
Wechat applet Development Tool Post net:: Err Proxy Connexion Problèmes d'agent défectueux
What are the key points often asked in the redis interview
Gbase 8C system table PG_ class
COM and cn
通达OA v12流程中心
Thread safe singleton mode