创建、更改和删除触发器Creating, Altering, and Removing Triggers

08/06/2017

本文内容

适用于:Applies to: SQL ServerSQL Server(所有支持的版本)SQL ServerSQL Server (all supported versions) Azure SQL 数据库Azure SQL DatabaseAzure SQL 数据库Azure SQL Database Azure SQL 托管实例Azure SQL Managed InstanceAzure SQL 托管实例Azure SQL Managed Instance Azure Synapse AnalyticsAzure Synapse AnalyticsAzure Synapse AnalyticsAzure Synapse Analytics适用于:Applies to: SQL ServerSQL Server(所有支持的版本)SQL ServerSQL Server (all supported versions) Azure SQL 数据库Azure SQL DatabaseAzure SQL 数据库Azure SQL Database Azure SQL 托管实例Azure SQL Managed InstanceAzure SQL 托管实例Azure SQL Managed Instance Azure Synapse AnalyticsAzure Synapse AnalyticsAzure Synapse AnalyticsAzure Synapse Analytics

在 SMO 中,触发器由 Trigger 对象表示。In SMO, triggers are represented by using the Trigger object. Transact-SQLTransact-SQL触发器对象的属性设置所激发的触发器时运行的代码 TextBody 。The Transact-SQLTransact-SQL code that runs when the trigger that is fired is set by the TextBody property of the Trigger object. 使用 Trigger 对象的其他属性(如 Update 属性)可以设置触发器的类型。The type of trigger is set by using other properties of the Trigger object, such as the Update property. 这是一个布尔属性,该属性指定是否由对父表上的记录的 更新 触发触发器。This is a Boolean property that specifies whether the trigger is fired by an UPDATE of records on the parent table.

Trigger 对象表示传统的数据操作语言 (DML) 触发器。The Trigger object represents traditional, data manipulation language (DML) triggers. 在 SQL Server 2008SQL Server 2008 和更改版本中,也同样支持数据定义语言 (DDL) 触发器。In SQL Server 2008SQL Server 2008 and later versions, data definition language (DDL) triggers are also supported. DDL triggers are represented by the DatabaseDdlTrigger object and the ServerDdlTrigger object.

示例Example

若要使用所提供的任何代码示例,您必须选择创建应用程序所需的编程环境、编程模板和编程语言。To use any code example that is provided, you will have to choose the programming environment, the programming template, and the programming language in which to create your application.

在 Visual Basic 中创建、更改和删除触发器Creating, Altering, and Removing a Trigger in Visual Basic

此代码示例演示如何在 AdventureWorks2012AdventureWorks2012 数据库中名为 Sales 的现有表上创建并插入更新触发器。This code example shows how to create and insert an update trigger on an existing table, named Sales, in the AdventureWorks2012AdventureWorks2012 database. 当更新表或插入新记录时触发器会发送提醒消息。The trigger sends a reminder message when the table is updated or a new record is inserted.

'Connect to the local, default instance of SQL Server.

Dim mysrv As Server

mysrv = New Server

'Reference the AdventureWorks2012 2008R2 database.

Dim mydb As Database

mydb = mysrv.Databases("AdventureWorks2012")

'Declare a Table object variable and reference the Customer table.

Dim mytab As Table

mytab = mydb.Tables("Customer", "Sales")

'Define a Trigger object variable by supplying the parent table, schema ,and name in the constructor.

Dim tr As Trigger

tr = New Trigger(mytab, "Sales")

'Set TextMode property to False, then set other properties to define the trigger.

tr.TextMode = False

tr.Insert = True

tr.Update = True

tr.InsertOrder = Agent.ActivationOrder.First

Dim stmt As String

stmt = " RAISERROR('Notify Customer Relations',16,10) "

tr.TextBody = stmt

tr.ImplementationType = ImplementationType.TransactSql

'Create the trigger on the instance of SQL Server.

tr.Create()

'Remove the trigger.

tr.Drop()

在 Visual C# 中创建、更改和删除触发器Creating, Altering, and Removing a Trigger in Visual C#

此代码示例演示如何在 AdventureWorks2012AdventureWorks2012 数据库中名为 Sales 的现有表上创建并插入更新触发器。This code example shows how to create and insert an update trigger on an existing table, named Sales, in the AdventureWorks2012AdventureWorks2012 database. 当更新表或插入新记录时触发器会发送提醒消息。The trigger sends a reminder message when the table is updated or a new record is inserted.

{

//Connect to the local, default instance of SQL Server.

Server mysrv;

mysrv = new Server();

//Reference the AdventureWorks2012 database.

Database mydb;

mydb = mysrv.Databases["AdventureWorks2012"];

//Declare a Table object variable and reference the Customer table.

Table mytab;

mytab = mydb.Tables["Customer", "Sales"];

//Define a Trigger object variable by supplying the parent table, schema ,and name in the constructor.

Trigger tr;

tr = new Trigger(mytab, "Sales");

//Set TextMode property to False, then set other properties to define the trigger.

tr.TextMode = false;

tr.Insert = true;

tr.Update = true;

tr.InsertOrder = ActivationOrder.First;

string stmt;

stmt = " RAISERROR('Notify Customer Relations',16,10) ";

tr.TextBody = stmt;

tr.ImplementationType = ImplementationType.TransactSql;

//Create the trigger on the instance of SQL Server.

tr.Create();

//Remove the trigger.

tr.Drop();

}

在 PowerShell 中创建、更改和删除触发器Creating, Altering, and Removing a Trigger in PowerShell

此代码示例演示如何在 AdventureWorks2012AdventureWorks2012 数据库中名为 Sales 的现有表上创建并插入更新触发器。This code example shows how to create and insert an update trigger on an existing table, named Sales, in the AdventureWorks2012AdventureWorks2012 database. 当更新表或插入新记录时触发器会发送提醒消息。The trigger sends a reminder message when the table is updated or a new record is inserted.

# Set the path context to the local, default instance of SQL Server and to the

#database tables in Adventureworks2012

CD \sql\localhost\default\databases\AdventureWorks2012\Tables\

#Get reference to the trigger's target table

$mytab = get-item Sales.Customer

# Define a Trigger object variable by supplying the parent table, schema ,and name in the constructor.

$tr = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Trigger `

-argumentlist $mytab, "Sales"

# Set TextMode property to False, then set other properties to define the trigger.

$tr.TextMode = $false

$tr.Insert = $true

$tr.Update = $true

$tr.InsertOrder = [Microsoft.SqlServer.Management.SMO.Agent.ActivationOrder]::First

$tr.TextBody = " RAISERROR('Notify Customer Relations',16,10) "

$tr.ImplementationType = [Microsoft.SqlServer.Management.SMO.ImplementationType]::TransactSql

# Create the trigger on the instance of SQL Server.

$tr.Create()

#Remove the trigger.

$tr.Drop()

mysql2005触发器修改成绩_创建、更改和删除触发器相关推荐

  1. sql 触发器未触发_学习SQL:SQL触发器

    sql 触发器未触发 SQL Triggers are another powerful database object we have at our disposal. In previous ar ...

  2. mysql之触发器详解_学习笔记之MySQL触发器详解

    触发器是由事件来触发某个操作,这些事件包括INSERT语句,UPDATE语句和DELETE语句 创建触发器 创建只有一个执行语句的触发器 CREATE TRIGGER 触发器名 BEFORE|AFTE ...

  3. linux忘记密码修改密码_如何更改我的Linux密码

    linux忘记密码修改密码 How to change my password on a Linux box? The original password is generated by the ad ...

  4. mysql 删除创建表分区_创建,增加,删除mysql表分区

    1.测试添加分区和删除分区 ###添加删除range分区 (1)创建一个分区: CREATE TABLE titles ( emp_no      INT NOT NULL, title        ...

  5. mysql 添加分区_创建,增加,删除mysql表分区

    1.测试添加分区和删除分区 ###添加删除range分区 (1)创建一个分区: CREATE TABLE titles ( emp_no      INT NOT NULL, title        ...

  6. orcle 删除表报正在使用_ORA-14452:试图创建,更改或删除正在使用的临时表中的索引...

    因为表kol_xx_fin050_temp 为临时表,而且有其他session正在使用. select vs.* from v$session vs , v$lock vl , dba_objects ...

  7. 用java面向对象的内容建立学生姓名,学号,id,班级,每一科的成绩,以及对管理员实现(对老师只实现查看):通过名字查询成绩,通过学号查询成绩,通过id修改姓名,通过姓名修改成绩

    这个问题如果用jsp和数据库的内容做那会非常简单,那么只用java面向对象来做呢?问题分析:本题首先需要建1.学生类2.班级类3.科目类4.对管理员和老师的接口(因为只有方法没有属性,用接口会简单一些 ...

  8. mysql的触发器实验报告_数据库原理实验报告s11-数据库触发器的创建.doc

    数据库原理实验报告s11-数据库触发器的创建.doc 数据库管理系统SQLSERVER实验报告第1页2011年5月4日实验11数据库触发器的建立实验日期和时间20141128实验室软件工程室班级12计 ...

  9. 【Linux】【服务器】 CentOS7下远程访问mysql数据库_创建用户及授予权限_查看用户、修改密码详细步骤

    一.创建用户 CREATE USER 'username'@'%' IDENTIFIED BY 'password'; username:你将创建的用户名: %:指定该用户在哪个主机上可以登录,%表示 ...

最新文章

  1. scuttle包对单细胞数据质控
  2. 2021暑假实习-SSM超市积分管理系统-day10笔记
  3. UE4 Slate Architecture
  4. Win32下显示、隐式加载DLL的方法
  5. SAP License:SAP Concur是什么?
  6. requireJS(一)
  7. springboot指定属性返回_Spring Boot 最最最常用的注解梳理
  8. torch.optim.lr_scheduler:调整学习率
  9. 设计图纸管理系统办公系统实现无纸化
  10. Frobenius标准型与Jordan标准型总结
  11. scsi是工作站和服务器硬盘,高速SAS硬盘与SCSI硬盘技术对比
  12. win10用什么清理垃圾好?
  13. Parallels Desktop的windows虚拟机无法打开iso文件
  14. 视频号怎么赚钱?4个赚钱小技巧,实现视频号流量变现!
  15. 阿里云 mysql 100_MySQL服务进程占用系统CPU达100%-阿里云开发者社区
  16. 基于51单片机的指纹解锁自动开门
  17. 【Vue】Vue 项目搭建
  18. auto.js之界面ui
  19. plcst语言编程教程_PLC ST语言编程之我的心得-专业自动化论坛-中国工控网论坛...
  20. 手工纸盒子_折纸盒子大全_10多种折纸盒子制作图解教程|怎么折纸盒子 - 聚巧网...

热门文章

  1. 大话细说ORM -----(转)
  2. Hadoop源代码分析(二)
  3. 博士期间要注意的几个问题
  4. python中parse是什么_Python中optparse模块使用浅析
  5. mysql linux 安装_mysql-5.7.28 在Linux下的安装教程图解
  6. 关于linux kernel编译的几项关键点:
  7. WinCE内核裁减(中文字体)及字库和内核的分离
  8. location.href属于重定向还是转发_servlet2 单元测试、转发、重定向
  9. php hasmany,浅谈laravel orm 中的一对多关系 hasMany
  10. 【转】DHF、DMR、MDF、DHR医疗器械文件要求与解读