使用代码创建触发器
2011-04-11 19:40
267 查看
![](http://pic002.cnblogs.com/images/2011/163244/2011041119372295.png)
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, DBTables, StdCtrls, Buttons; type TForm1 = class(TForm) Memo1: TMemo; Memo2: TMemo; Label1: TLabel; BitBtn1: TBitBtn; BitBtn2: TBitBtn; DataSource1: TDataSource; Query1: TQuery; procedure BitBtn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.BitBtn1Click(Sender: TObject); begin try with Query1 do begin close; SQL.clear; SQL.Add('create trigger test on 学生表'); SQL.Add('instead of insert as drop table 教师表'); ExecSQL; end; Application.MessageBox('触发器创建成功!','提示',64); Except Application.MessageBox('触发器创建失败!','提示',64); end; end; end.
Create Trigger 的语法格式:
------------------------------------------------------------
Create Trigger Trigger_name
On {table|view}
[with Encryption]
{For|After|Instead of} {[Delete] [,] [Insert] [,] [Update]}
As
Sql_statements
-------------------------------------------------------------
Trigger_name 为要创建的触发器名称。触发器名称在数据库中必须是惟一的。
table|view 表示在哪个表或视图上建立触发器。
with Encryption 对触发器进行加密。防止将触发器作为Sql Server 复制的一部分发布。
Instead of 指定执行触发器而不是执行触发SQL语句,从而替代触发语句的操作。
{[Delete] [,] [Insert] [,] [Update]} 是指定在表或视图上执行哪些数据修改语句时将激活触发器的关键字。必须至少指定一个选项。
As 表示触发器要执行的操作。
Sql_statements 表示触发器的条件与操作。
相关文章推荐
- [Silverlight]通过SilverlightLoader使用托管代码创建自定义载入界面(Splash Screen) (上)
- SSM框架——使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 初识GihHub,创建仓库,使用GitHub for Windows 同步本地代码文件,创建分支
- 数据库-数据库、基本表、视图的创建,触发器的使用
- 使用org.apache.lucene创建和查询索引核心代码详解
- 使用MyBatis Generator自动创建代码
- 详解Spring Boot 使用Java代码创建Bean并注册到Spring中
- 使用Spring Boot创建Web应用程序的示例代码
- 使用IO技术,创建一个目录,然后复制一个文件到该目录!实现复制的功能。(在博客园上传的第一份代码)
- C# 2.0:使用匿名方法、迭代程序和局部类来创建优雅的代码
- SSM框架——使用MyBatis Generator自动创建代码
- Android 在Java代码中设置style属性--使用代码创建ProgressBar对象
- Spring Boot 使用Java代码创建Bean并注册到Spring中
- 第一次使用GIT,创建仓库并提交项目代码
- SSM框架——使用MyBatis Generator自动创建代码
- SSM框架——使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 关于实体类的创建简化代码Lombok的使用
- 数据库-数据库、基本表、视图的创建,触发器的使用