Skip to main content
Creates a new SQL procedure.
CREATE PROCEDURE Syntax
When any of the source tables referenced by a SQL procedure is altered or dropped, the SQL procedure will also be dropped.

Parameters

<schema name>

Name of the schema in which this SQL procedure will be created.

<procedure name>

Name to give to the created SQL procedure; must adhere to the supported naming criteria for tables, and cannot be named the same as any existing table or view.

<sql statements>

Semicolon-separated list of supported SQL statements. If the final statement in the SQL procedure is an output-generating statement (SQL query, SHOW command, etc.), the output of that statement alone will be returned to the user; all other statements that generate output will be ignored.

OR REPLACE

Drop any existing SQL procedure with the same name before creating this one.

LANGUAGE

Optional language specification. Only SQL is supported at this time.

EXECUTE FOR EVERY

Allows specification of an interval in seconds, minutes, hours, or days, at which the SQL procedure should be executed. Fractional values for <number> are accepted.By default, the procedure will be run immediately and every specified interval after that; this can be modified with the following options:
  • STARTING AT: specify a date or timestamp at which the first execution should occur
  • STOP AFTER: specify a date, timestamp, or time interval after which executions should end

WITH OPTIONS

Optional indicator that a comma-delimited list of option/value assignments will follow. The following options are available:
OptionDescription
EXECUTE ASExecutes the SQL procedure as the given user with that user’s privileges.
If this user doesn’t exist at the time of execution, the SQL procedure will be executed as the creating user, and and, failing that, the system administration user.

Examples

To create a sqlp SQL procedure:
CREATE PROCEDURE Example
To create a sqlp_weekly SQL procedure that executes once per week:
CREATE PROCEDURE (Scheduled) Example