当前位置:网站首页>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
边栏推荐
- 简单理解svg
- 【ROS进阶篇】第六讲 ROS中的录制与回放(rosbag)
- GBase 8c系统表-pg_auth_members
- Compréhension simple de SVG
- Producer consumer model based on thread pool (including blocking queue)
- require. context
- [Yu Yue education] China Ocean University job search OMG reference
- Packing and unpacking of JS
- stm32F407-------ADC
- [tutorial] chrome turns off cross domain policies CORS and samesite, and brings cookies across domains
猜你喜欢
内存池(内核角度理解new开辟空间的过程)
Use go language to realize try{}catch{}finally
SPI mechanism
Flink CDC mongoDB 使用及Flink sql解析monggo中复杂嵌套JSON数据实现
Machine learning notes (constantly updating...)
使用Go语言实现try{}catch{}finally
Deep learning notes (constantly updating...)
Recommendation letter of "listing situation" -- courage is the most valuable
[shutter] pull the navigation bar sideways (drawer component | pageview component)
[shutter] shutter debugging (debugging fallback function | debug method of viewing variables in debugging | console information)
随机推荐
GBase 8c系统表-pg_conversion
[Yu Yue education] reference materials of chemical experiment safety knowledge of University of science and technology of China
Qt之QComboBox添加QCheckBox(下拉列表框插入复选框,含源码+注释)
Coroutinecontext in kotlin
[tutorial] chrome turns off cross domain policies CORS and samesite, and brings cookies across domains
Restcloud ETL cross database data aggregation operation
Method of removing webpage scroll bar and inner and outer margins
Detailed introduction to the deployment and usage of the Nacos registry
Tongda OA homepage portal workbench
基于线程池的生产者消费者模型(含阻塞队列)
【CodeForces】CF1338A - Powered Addition【二进制】
[shutter] top navigation bar implementation (scaffold | defaulttabcontroller | tabbar | tab | tabbarview)
iptables 4层转发
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
Packing and unpacking of JS
MySQL learning 03
微服务组件Sentinel (Hystrix)详细分析
Cancellation of collaboration in kotlin, side effects of cancellation and overtime tasks
y54.第三章 Kubernetes从入门到精通 -- ingress(二七)