当前位置:网站首页>Gbase 8C trigger (I)
Gbase 8C trigger (I)
2022-07-03 02:22:00 【Dazhuang twelve】
Trigger functions can use most of the available procedural languages , Include PL/pgSQL、PL/Tcl、PL/Perl and PL/Python. Trigger is a mechanism that database provides programmers and data analysts to ensure data integrity , It is a special stored procedure related to data table events . The execution of the trigger is not called by the program , There is no need to open it manually , It is triggered by events on the data table , When users add to a data table 、 Delete 、 When the operation is changed, it will be activated to execute .
A trigger declares that the database should automatically execute a special function when performing a specific type of operation . Triggers can be attached to tables ( Partition or no partition )、 Views and external tables .
On tables and external tables , Triggers can be defined as INSERT、UPDATE or DELETE The operation is performed before or after , Can be for each SQL The statement is executed once or once for each modified row .UPDATE Triggers can be further set to target only UPDATE Of the statement SET Clause starting from a specific column . Triggers can also be TRUNCATE Statement trigger . If a trigger event occurs , The trigger function will be called at the appropriate event to handle the event .
On the view , Triggers can be defined to replace INSERT、UPDATE or DELETE Operation execution .INSTEAD OF The trigger triggers once for each row in the view that needs to be modified . The responsibility of the trigger function is to make necessary changes to the underlying basic table , And when appropriate, return the modified row for display in the view . Triggers on views can also be defined for each SQL Statement is executed once , stay INSERT\UPDATE or DELETE Before or after the operation .
The trigger function must be defined before the trigger itself is created . Trigger function must be defined as a function without parameters , And the return type is trigger( Trigger function is passed through a special TriggerData Structure as its input , Not in the form of ordinary function parameters ).
Once a suitable trigger function is created , You can use CREATE TRIGGER Set up triggers . The same trigger function can be used for multiple triggers .
GBase 8c Provide triggers for each row and each statement at the same time . For a trigger per row , For each line modified by the statement that triggers the trigger, the trigger function will be called once . contrary , A trigger of each statement is called only once for its triggering statement , No matter how many lines the statement affects . Specially , A statement that does not affect any rows will still result in the execution of any available triggers per statement . These two types of triggers are sometimes called row level triggers and statement level triggers respectively .TRUNCATE Triggers on can only be defined at the statement level , Instead of defining each line .
Triggers can also depend on whether they are before the operation 、 Trigger later , Or be triggered to replace the operation to classify . They refer to BEFORE trigger 、AFTER Triggers and INSTEAD OF trigger . Sentence level BEFORE Triggers are triggered before the statement starts doing anything , And statement level AFTER Triggers are triggered after the statement finishes everything . These trigger types can be defined in the table 、 View or external table . Row level BEFORE Triggers are triggered before each row is manipulated , And row level AFTER The trigger is triggered after the end of the statement ( But at any statement level AFTER Before trigger ). These trigger types can only be defined on non partitioned tables and external tables , Cannot be defined on a view .INSTEAD OF Triggers can only be defined on views , And can only be defined as row level ; They immediately trigger for each row in the view that is identified as needing to be manipulated .
边栏推荐
- Summary of ES6 filter() array filtering methods
- 返回一个树形结构数据
- GBase 8c触发器(二)
- Face recognition 6-face_ recognition_ Py based on OpenCV, face detection and real-time tracking using Haar cascade and Dlib Library
- What are the key points often asked in the redis interview
- Method of removing webpage scroll bar and inner and outer margins
- GBase 8c 函数/存储过程参数(二)
- RestCloud ETL 跨库数据聚合运算
- 力扣(LeetCode)183. 从不订购的客户(2022.07.02)
- 苏世民:25条工作和生活原则
猜你喜欢
随机推荐
Gbase 8C system table PG_ conversion
PyTorch 卷积网络正则化 DropBlock
GBase 8c系统表-pg_conversion
4. 类和对象
GBase 8c系统表-pg_amop
Detailed analysis of micro service component sentinel (hystrix)
Compréhension simple de SVG
CFdiv2-Fixed Point Guessing-(區間答案二分)
Distributed transaction solution
Producer consumer model based on thread pool (including blocking queue)
【教程】chrome關閉跨域策略cors、samesite,跨域帶上cookie
Cvpr2022 remove rain and fog
GBase 8c系统表-pg_collation
线程安全的单例模式
awk从入门到入土(2)认识awk内置变量和变量的使用
Leetcode(540)——有序数组中的单一元素
Socket programming
QT qcombobox add qccheckbox (drop-down list box insert check box, including source code + comments)
The Sandbox阐释对元宇宙平台的愿景
y54.第三章 Kubernetes从入门到精通 -- ingress(二七)







