Search code examples
db2sequenceresetschedule

DB2 reset sequence midnight everyday


I need to auto reset a DB2 sequence every midnight .i have tried with admin tasks with sample i found in Example 1( https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.sql.rtn.doc/doc/r0054371.html ).Even this got executed and show in systools.admin_task_list,It didn't reset sequence at midnight. No items in systools.admin_task_status.how can I get errors related to admin tasks ?

Is there more easy way of resetting a DB2 sequence daily ?

CALL SYSPROC.ADMIN_TASK_ADD
  ('Reset_sales1_seq',
    CURRENT_TIMESTAMP,
    NULL,
    NULL,
    '0 0 * * *',
    'SYSPROC',
    'ADMIN_CMD',
    'VALUES("ALTER SEQUENCE Sample.sales1_seq RESTART WITH 1")',
    NULL,
    NULL )

Solution

  • You are using stored procedure ADMIN_CMD which only runs a specific selection of commands as detailed in the documentation .

    Know the difference between plain SQL/DDL and commands.

    ADMIN_CMD is not for running plain SQL statements directly like ALTER SEQUENCE.

    Consider writing a simple stored-procedure to perform the ALTER SEQUENCE action in dynamic SQL, and then calling that procedure directly in the ADMIN_TASK_ADD.