SAP Sybase IQ EVENT Each time a scheduled event handler is completed

16.0 SP04 > Reference: Statements and Options > SQL Statements

Defines an event and its associated handler for automating predefined actions. Also defines scheduled actions.

Quick Links:

Go to Parameters

Go to Examples

Go to Usage

Go to Standards

Go to Permissions

Syntax

CREATE EVENT event-name
   [ TYPE event-type
       [ WHERE trigger-condition [ AND trigger-condition ], ...]
       | SCHEDULE schedule-spec, … ]
   …[ ENABLE | DISABLE ]
   …[ AT { CONSOLIDATED | REMOTE | ALL } ]
   …[ HANDLERBEGIN
   …
      END ]

event-type - (back to Syntax)BackupEnd
     |  “Connect”  
     |  ConnectFailed 
     |  DatabaseStart 
     |  DBDiskSpace 
     |  “Disconnect” 
     |  GlobalAutoincrement 
     |  GrowDB 
     |  GrowLog 
     |  GrowTemp   
     |  IQMainDBSpaceFree 
     |  IQTempDBSpaceFree 
     |  LogDiskSpace 
     |  “RAISERROR” 
     |  ServerIdle 
     |  TempDiskSpacetrigger-condition - (back to Syntax)event_condition( condition-name )
     { =
       | <
       | >
       | !=
       | <=
       | >= }  valueschedule-spec - (back to Syntax)schedule-name ]
     { START TIME start-time | BETWEEN start-time AND end-time }
     [ EVERY period { HOURS  |  MINUTES  | SECONDS } ]
     [ ON { ( day-of-week, … ) | ( day-of-month, … ) } ]
     [ START DATE start-date ]

Parameters

(back to top)

  • event-name – an event has a creator, which is the user creating the event, and the event handler executes with the permissions of that creator. This is the same as stored procedure execution. You cannot create events owned by other users. You can list event names by querying the system table SYSEVENT. For example:

    SELECT event_id, event_name FROM SYS.SYSEVENT
  • event-type – one of a set of system-defined event types. The event types are case-insensitive. To specify the conditions under which this event-type triggers theevent, use the WHERE clause.

    • DiskSpace – if the database contains an event handler for one of the DiskSpace types, the database server checks the available space on each device associated with the relevant file every 30 seconds.

      In the event the database has more than one dbspace, on separate drives, DBDiskSpace checks each drive and acts depending on the lowest available space.
    • LogDiskSpace – checks the location of the transaction log and any mirrored transaction log, and reports based on the least available space.
    • Globalautoincrement – fires when the GLOBAL AUTOINCREMENT default value for a table is within one percent of the end of its range. A typical action for the handler could be to request a new value for the GLOBAL_DATABASE_ID clause.

      You can use the EVENT_CONDITION function with RemainingValues as an argument for this event type.
    • ServerIdle – if the database contains an event handler for the ServerIdle type, the server checks for server activity every 30 seconds.
  • WHERE clause – the trigger condition determines the condition under which an event is fired. For example, to take an action when the disk containing the transaction log becomes more than 80% full, use this triggering condition:

    ...
    WHERE event_condition( ‘LogDiskSpacePercentFree‘ ) < 20
    ...

    The argument to the EVENT_CONDITION function must be valid for the event type. You can use multiple AND conditions to make up the WHERE clause, but you cannot use OR conditions or other conditions.

  • SCHEDULE – specifies when scheduled actions are to take place. The sequence of times acts as a set of triggering conditions for the associated actions defined in the event handler.You can create more than one schedule for a given event and its associated handler. This permits complex schedules to be implemented. While it is compulsory to provide a schedule name when there is more than one schedule, it is optional if you provide only a single schedule.

    You can list schedule names by querying the system table SYSSCHEDULE. For example:

    SELECT event_id, sched_name FROM SYS.SYSSCHEDULE

    Each event has a unique event ID. Use the event_id columns of SYSEVENT and SYSSCHEDULE to match the event to the associated schedule.

    When a nonrecurring scheduled event has passed, its schedule is deleted, but the event handler is not deleted.

    Scheduled event times are calculated when the schedules are created, and again when the event handler completes execution. The next event time is computed by inspecting the schedule or schedules for the event, and finding the next schedule time that is in the future. If an event handler is instructed to run every hour between 9:00 and 5:00, and it takes 65 minutes to execute, it runs at 9:00, 11:00, 1:00, 3:00, and 5:00. If you want execution to overlap, you must create more than one event.

    The subclauses of a schedule definition are as follows:

    • START DATE – the date on which scheduled events are to start occurring. The default is the current date.
    • START TIME – the first scheduled time for each day on which the event is scheduled. If a START DATE is specified, the START TIME refers to that date. If no START DATE is specified, the START TIME is on the current day (unless the time has passed) and each subsequent day.
    • BETWEEN … AND – a range of times during the day outside of which no scheduled times occur. If a START DATE is specified, the scheduled times do not occur until that date.
    • EVERY – an interval between successive scheduled events. Scheduled events occur only after the START TIME for the day, or in the range specified by BETWEEN …AND.
    • ON – a list of days on which the scheduled events occur. The default is every day. These can be specified as days of the week or days of the month.

      Days of the week are Monday, Tuesday, and so on. The abbreviated forms of the day, such as Mon, Tue, and so on, may also be used. The database server recognizes both full-length and abbreviated day names in any of the languages supported by SAP Sybase IQ.

      Days of the month are integers from 0 to 31. A value of 0 represents the last day of any month.

    Each time a scheduled event handler is completed, the next scheduled time and date is calculated.

    • If the EVERY clause is used, find whether the next scheduled time falls on the current day, and is before the end of the BETWEEN …AND range. If so, that is the next scheduled time.
    • If the next scheduled time does not fall on the current day, find the next date on which the event is to be executed.
    • Find the START TIME for that date, or the beginning of the BETWEEN … AND range.
  • ENABLE | DISABLE – by default, event handlers are enabled. When DISABLE is specified, the event handler does not execute even when the scheduled time or triggering condition occurs. A TRIGGER EVENT statement does not cause a disabled event handler to be executed
  • AT – to execute events at remote or consolidated databases in a SQL Remote setup, use this clause to restrict the databases at which the event is handled. By default, all databases execute the event.
  • HANDLER – each event has one handler. Like the body of a stored procedure, the handler is a compound statement. There are some differences, though: you can use an EXCEPTION clause within the compound statement to handle errors, but not the ON EXCEPTION RESUME clause provided within stored procedures.

Examples

(back to top)

  • Example 1 – instructs the database server to carry out an automatic incremental backup daily at 1 a.m.:

    CREATE EVENT IncrementalBackup
    SCHEDULE
    START TIME ‘1:00AM‘ EVERY 24 HOURS
    HANDLER
      BEGIN
        BACKUP DATABASE INCREMENTAL
        TO ‘backups/daily.incr‘
      END
  • Example 2 – instructs the database server to call the system stored procedure sp_iqspaceused every 10 minutes, then store in a table the returned current date and time, the current number of connections to the database, and current information about the use of main and temporary IQ store:

    CREATE TABLE mysummary(dt DATETIME,
      users INT, mainKB UNSIGNED BIGINT,
      mainPC UNSIGNED INT,
      tempKB UNSIGNED BIGINT,
      tempPC UNSIGNED INT) ;
    CREATE EVENT mysummary
      SCHEDULE sched_mysummary
        START TIME ‘00:01 AM‘ EVERY 10 MINUTES
      HANDLER
      BEGIN
        DECLARE mt UNSIGNED BIGINT;
        DECLARE mu UNSIGNED BIGINT;
        DECLARE tt UNSIGNED BIGINT;
        DECLARE tu UNSIGNED BIGINT;
        DECLARE conncount UNSIGNED INT;
    
        SET conncount = DB_PROPERTY(‘ConnCount‘);
        CALL SP_IQSPACEUSED(mt,mu,tt,tu);
    
    		INSERT INTO mysummary VALUES( NOW(),
        conncount, mu, (mu*100)/mt, tu,
        (tu*100)/tt );
    	END;
  • Example 3 – posts a message to the server log when free disk space on the device containing the transaction log file falls below 30 percent, but execute the handler no more than once every 300 seconds.

    CREATE EVENT LowTxnLogDiskSpace
    TYPE DBDiskSpace
    WHERE event_condition( ‘DBFreePercent‘ ) < 30
    AND event_condition( ‘Interval‘ ) >= 300
    HANDLER
    BEGIN
    message ‘Disk space for Transaction Log is low.‘;
    END;

Usage

(back to top)

An event definition includes two distinct pieces. The trigger condition can be an occurrence, such as a disk filling up beyond a defined threshold. A schedule is a set of times, each of which acts as a trigger condition. When a trigger condition is satisfied, the event handler executes. The event handler includes one or more actions specified inside a compound statement (BEGIN... END).

If no trigger condition or schedule specification is supplied, only an explicit TRIGGER EVENT statement can trigger the event. During development, you might want to develop and test event handlers using TRIGGER EVENT and add the schedule or WHERE clause once testing is complete.

Event errors are logged to the database server console.

When event handlers are triggered, the server makes context information, such as the connection ID that caused the event to be triggered, available to the eventhandler using the EVENT_PARAMETER function.

Note: Although statements that return result sets are disallowed in events, you can allow an event to call a stored procedure and insert the procedure results into a temporary table.

Side Effects:

  • Automatic commit.
  • The actions of an event handler are committed if no error is detected during execution, and rolled back if errors are detected.

Standards

(back to top)

  • SQL—Vendor extension to ISO/ANSI SQL grammar.
  • SAP Sybase Database product—Not supported by Adaptive Server.

Permissions

(back to top)

Requires one of:

  • MANAGE ANY EVENT system privilege.
  • CREATE ANY OBJECT system privilege.

Event handlers execute on a separate connection, with the privileges of the event owner. To execute with privileges other than MANAGE ANY EVENT system privilege, you can call a procedure from within the event handler: the procedure executes with the permissions of its owner. The separate connection does not count towards the ten-connection limit of the personal database server.

Parent topic: SQL Statements

Related reference

ALTER EVENT Statement

BEGIN … END Statement

COMMENT Statement

DROP Statement

TRIGGER EVENT Statement


Created May 13, 2014. Send feedback on this help topic to Technical Publications: [email protected]

来源: <http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc00801.1604/doc/html/san1281564795620.html?resultof=%22%65%76%65%6e%74%22%20>

来自为知笔记(Wiz)

时间: 2024-10-26 05:56:28

SAP Sybase IQ EVENT Each time a scheduled event handler is completed的相关文章

SAP Sybase IQ 操作基础

1.启动 source IQ-16_0.sh 命令行查看安装程序是否成功 start_iq -v2 2.数据库.表空间 start_iq -n utility_db dbisql -c 'uid=dba;pwd=sql;eng=utility_db;dbn=utility_db' -nogui -- 建立数据库 (DBA)> CREATE DATABASE '/sybaseiq160/T2/anos.db' IQ PATH '/sybaseiq160/T2/iq_system_main.iq'

SAP sybase培训笔记4-使用技巧&&Query Plan

解释型与预编译型 1.传统的数据库,存储过程有comp的过程,IQ不做. 2.!!!存储过程性能吞吐量要比直接查询降一半. 3.IQ内部,多个语句会分析并转换成存储过程去执行.所以语句多一次执行,语句少直接逐句执行. 4. 使用索引 简化条件 选择算法 join group 行数 cpu distinct记录数 等等,决定了语法选择. 5. Query Plan开关: Query_Plan='ON', 只有叶子节点才有 condition execution set TEMPORARY OPTI

Sybase IQ如何将大文件数据迅速加载到数据库

试想一下,如果一个文件5G.10G甚至更大.如何将它迅速地加载到数据库指定的表呢?我们看看Sybase IQ是如何迅速地将表的数据加载到数据库的. 数据文件格式: 1440,2011-01-09 00:00:00,1,珠海,1,C网,8612345678222,221943,1,12175,1,12,14426467,1191632,9,1440,2011-01-09 00:00:00,1,珠海,1,C网,8612345678222,968852,1,82077,1,7,2430696,1349

sybase iq数据库load表字符集乱码

公司领导要我导一个文件到sybase iq数据库一张表中,load表语句如下: load table kyfx_ci_loc(  city_name ',',   county_id  ci_name ',',  ci_section ',',  ci_id ',',  ci_longtitude_gps ',',  ci_latitude_gps ',',  ci_longtitude_baidu ',',  ci_latitude_baidu 0x0a)  using file '/home

SAP sybase培训笔记2

1.考虑数据规划,存储空间有多少等等. 按照公式估算: 字符集.排序.页面大小创建后不能更改. 数据存储空间规划,特别是集群模式的部署 LUN Plan要点. IQ使用的磁盘,物理上必须要与其它应用隔离: RAID 5/6 不要用LVM 尽量分散I/O 1.建议先打补丁再建库. 2.准备文件系统 建议给数据库日志信息(serverlog/iqmsg)等分配一个独立的文件系统,避免日志撑爆. start_iq -n iqdemo iqdemo.db ... <other options> ...

Sybase IQ使用过程中注意事项

Sybase IQ使用过程中注意事项 1,字母大小写比对不敏感,也就是在值比对判断时大小写字母都一样; 2,等值,或<>判断,系统默认对等式两边比对值去右边空格再进行比较: 3,GROUP BY 可以根据SELECT字段或表达式的别名来 汇总,在编写时也尽量避免SELECT 语句的别名与FROM表中的字段有重复,不然会出现莫名其妙的错误: 4,FROM后的子查询 要定义别名才可使用: 5,存储过程要返回IQ系统错误信息 SQLCODE || ERRORMSG(*) :(两者都为EXCEPTIO

[DOM Event Learning] Section 1 DOM Event 处理器绑定的几种方法

[DOM Event Learning] Section 1 DOM Event处理器绑定的几种方法 网页中经常需要处理各种事件,通常的做法是绑定listener对事件进行监听,当事件发生后进行一些特定处理. 监听事件的几种方法如下文. 第一种,写在页面标签里面 <button onclick="alert('Hello')">Say hello</button> 上面这行代码,将按钮点击后的弹窗操作在标签声明的时候就绑定了. 这是一种糟糕的方法,原因如下: 1

DOM Event:事件流动(Event Flow)

考虑这么个例子: <div> <button id="btn">Click Me!</button> </div> 哪怕一个web开发的初学者都会知道,当我们鼠标在button上点击时,会在button上触发一个click事件.但是: button是div的一个子Node:从界面上来看,在button里点击相当于在div里点击:那click事件也会触发在div上吗? 如果click事件也触发在div上,那它们会不会共用同一个事件对象? 如

SAP sybase培训笔记1

historical data store (HDS) 1.对数据的使用是大批量的时候,不会对数据进行一条一条增删改这样的操作,这种场景是适合IQ的. 考察数据系统:吞吐量.响应时间 iq相应时间不见得快: 加载之后要批量维护索引:建议不要每分钟一次这样做,尽量积攒一下,比如10分钟做一次. 2. infocenter.sybase.com/help/index.jsp 要重视iq手册 1/端口 缺省值: 2/监控平台:sccadmin scc 密码(用于监控): 3/no 4)测试: >sta