首页 > 代码库 > SQL Server 触发器

SQL Server 触发器

定义:

  create trigger trigger_name on table_name

  with encryption | execute as [...]

  after | instead of 

  insert | delete | update

  as 

  #000000

  #000000

  ---------

  通过 inserted 表 deleted 表对数据进行操作。

  ---------------------------------------------------------------------------------------------------------------------------------------------------

  create table T1(X int ,Y int);
  create table T2(X int ,Y int );
  go

  create trigger tri_for_T1
  on T1
  after insert
  as

    insert into T2(X,Y) select X ,Y from deleted;
  go

----------------------------------------------------------------------------------------------------------------------------------------

  注意:

    如果在触发器中 rollback 引起触发器的事务也会被回滚。(说明它们是在同一个事务中的,不管是after 还是inserted of)

 

 

 

 

 

 

SQL Server 触发器