当前位置:网站首页>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
边栏推荐
- GBase 8c系统表-pg_constraint
- COM and cn
- 线程安全的单例模式
- How to find summer technical internship in junior year? Are you looking for a large company or a small company for technical internship?
- Coroutinecontext in kotlin
- Introduce in detail how to communicate with Huawei cloud IOT through mqtt protocol
- Job object of collaboration in kotlin
- Startup mode and scope builder of collaboration in kotlin
- y54.第三章 Kubernetes从入门到精通 -- ingress(二七)
- 【教程】chrome關閉跨域策略cors、samesite,跨域帶上cookie
猜你喜欢

返回一个树形结构数据

What are MySQL locks and classifications

Awk from introduction to earth (0) overview of awk

Recommendation letter of "listing situation" -- courage is the most valuable

RestCloud ETL 跨库数据聚合运算

创建+注册 子应用_定义路由,全局路由与子路由

Wechat applet Development Tool Post net:: Err Proxy Connexion Problèmes d'agent défectueux

Deep learning notes (constantly updating...)

udp接收队列以及多次初始化的测试

Tongda OA V12 process center
随机推荐
Codeforces Round #418 (Div. 2) D. An overnight dance in discotheque
CFdiv2-Fixed Point Guessing-(區間答案二分)
Face recognition 6-face_ recognition_ Py based on OpenCV, face detection and real-time tracking using Haar cascade and Dlib Library
GBase 8c系统表pg_cast
Stm32f407 ------- IIC communication protocol
Simple understanding of SVG
Gbase 8C system table PG_ authid
[Flutter] dart: class;abstract class;factory;类、抽象类、工厂构造函数
leetcode961. Find the elements repeated N times in the array with length 2n
Machine learning process and method
[shutter] shutter debugging (debugging fallback function | debug method of viewing variables in debugging | console information)
单词单词单词
簡單理解svg
5. File operation
Monitoring and management of JVM
Pytorch convolution network regularization dropblock
Awk from getting started to being buried (2) understand the built-in variables and the use of variables in awk
使用Go语言实现try{}catch{}finally
How to deal with cache hot key in redis
[shutter] bottom navigation bar implementation (bottomnavigationbar bottom navigation bar | bottomnavigationbaritem navigation bar entry | pageview)