Triggers vs Cursors
In a database, a trigger is a procedure (code segment) that is executed automatically when some specific events occur in a table/view. Among its other uses, triggers are mainly used for maintaining integrity in a database. A cursor is a control structure used in databases to go through the database records. It is very similar to the iterator provided by many programming languages.
What are Triggers?
触发器是一个过程(代码段),当某些特定事件发生在数据库的表/视图中时,它会自动执行。除其他用途外,触发器主要用于维持数据库中的完整性。触发器还用于执行业务规则,审核数据库中的更改和复制数据。最常见的触发因素是数据操纵语言(DML)触发器,这些触发器是在操纵数据时会触发的。一些数据库系统支持非数据触发器,这些数据库系统在发生数据定义语言(DDL)事件时会触发。一些示例是创建表,提交或回滚操作期间发射的触发器,等等。这些触发器可特别用于审核。Oracle数据库系统支持架构级触发器(即修改数据库模式时触发的触发器),例如在创建后,更改后,ALTER,ALTER,drow,Drow,Drow,Drow,Drop之后等。由Oracle支持的四种主要类型的触发器是RORACLE SEAR SEAR SEAR SERCAL SERCAL SERCAL SERCAL SERCAL SERCAL SERCAL SERCAL SERCAL SERCAL SERCAL FARGERS是ROW LES REVEL LEVEL TRIGGERS,ROW LEVEL TRIGGERS,READ LEVEL TREGGERS,,,,,,级别。列级触发,每个行类型触发器以及每个语句类型触发器。
What are Cursors?
一个cursor is a control structure used in databases to go through the database records. It is very similar to the iterator provided by many programming languages. In addition to traversing through records in a database, cursors also facilitate data retrieval, adding and deleting records. By defining the correct way, cursors can also be used to traverse backwards. When a SQL query returns a set of rows, those are actually processed using cursors. A cursor needs to be declared and assigned a name, before it could be used. Then the cursor needs to be opened using the OPEN command. This operation would place the cursor just before the first row of the result set of records. Then the cursor has to perform the FETCH operation to actually get a row of data in to the application. Finally, the cursor has to be closed using the CLOSE operation. Closed cursors can be opened again.
What is the difference between Triggers and Cursors?
一个trigger is a procedure (code segment) that is executed automatically when some specific events occur in a table/view of a database, while a cursor is a control structure used in databases to go through the database records. A cursor can be declared and used within a trigger. In such a situation, the declare statement would be inside the trigger. Then the scope of the cursor would be limited to that trigger. Within a trigger, if a cursor is declared on an inserted or a deleted table, such a cursor would not be accessible from a nested trigger. Once a trigger is completed, all the cursors created within the trigger will be de-allocated.
Leave a Reply