Database triggers

Excerpt from Baidu Encyclopedia: Trigger (trigger) SQL server is available to programmers and data analysts a way to ensure data integrity, which is associated with table event special stored procedure , its implementation is not called by the program, nor is started manually, but is triggered by an event , such as when a table operation (insert, delete, update) will be activated to perform it . Triggers are often used to enhance data integrity constraints and business rules and so on.

Type flip-flop

  Trigger into statement-level triggers and row-level triggers (for each row)

  1) statement-level trigger: is executed once, no matter how many rows affected will only be executed once before the specified operation or after the statement.

  2) row-level triggers: Trigger each record statements have been triggered action is affecting how many rows are triggered many times. Old and new recording using dummy variable, the value identifying the row level trigger state.

: Old representative of the old record, the record before the update ------: new represents new record

Trigger basic syntax:

    create [or replace] trigger trigger_name
      before|after
      delete|insert|update [of 列名]
      on 表名
      [for each row [where 条件]]
    declare
      ...
    begin
      plsql块
    end trigger_name

For example: After inserting employees print a word

  create or replace trigger inputtest
    before insert on person
  declare
  begin
    dbms_output.put_line('欢迎新员工');
  end inputtest;

insert into person values(123,'jason','hello');

The results output: Welcome new employees.

Meaning directive action statement and the following table:

Note that: the trigger can not commit the transaction, the transaction can not be rolled back. If an error occurs you need to throw an exception.

These are the basics of flip-flops and simple application. 

Guess you like

Origin www.cnblogs.com/jasonboren/p/10957050.html