Creating a trigger to only run when a new table is being created(创建仅在创建新表时运行的触发器)
问题描述
我知道我可以用它来创建 DDL 创建触发器;
I know that I can use this to create DDL create trigger;
CREATE OR REPLACE TRIGGER
create_table_trigger
AFTER CREATE ON SCHEMA
DECLARE
BEGIN
END;
问题是这个触发器会在像创建序列"这样的 DDL 上运行;我如何只对创建表"DDL 执行此操作?
Problem is this trigger would run on DDLs like 'Create sequence'; how can I only execute this for 'Create Table' DDLs?
推荐答案
CREATE OR REPLACE TRIGGER
create_table_trigger
AFTER CREATE ON SCHEMA
BEGIN
IF SYS.DICTIONARY_OBJ_TYPE = 'TABLE' THEN
....
END;
有关 EVENT 属性的列表,请参阅此页面
http://ist.marshall.edu/ist480adbp/plsql_triggers.html(链接是下)
For a list of EVENT attributes, refer to this page
http://ist.marshall.edu/ist480adbp/plsql_triggers.html (link is down)
Wayback machine 链接到上面死链接的内容:https://web.archive.org/web/20110809071133/http://ist.marshall.edu/ist480adbp/plsql_triggers.html
Wayback machine link to the contents of the dead link above: https://web.archive.org/web/20110809071133/http://ist.marshall.edu/ist480adbp/plsql_triggers.html
据我所知,dictionary_obj_type 是其中之一表|序列|过程|索引|功能|类型|包装
As far as I know, dictionary_obj_type is one of TABLE|SEQUENCE|PROCEDURE|INDEX|FUNCTION|TYPE|PACKAGE
而dictionary_obj_name 只是表/序列/过程/等的名称.
And dictionary_obj_name is just the name of the table/sequence/proc/etc.
- dictionary_obj_type 返回触发触发器的 DDL 操作发生的字典对象的类型.
- dictionary_obj_name 返回触发触发器的 DDL 操作发生的字典对象的名称.
- dictionary_obj_type Returns the type of the dictionary object on which the DDL operation that fired the trigger occurred.
- dictionary_obj_name Returns the name of the dictionary object on which the DDL operation that fired the trigger occurred.
这篇关于创建仅在创建新表时运行的触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:创建仅在创建新表时运行的触发器
基础教程推荐
- SQL Server 2016更改对象所有者 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01