Chapter 18. Stored Programs and Views
Table of Contents
18.3. Using Triggers ................................................................................................................ 1697
18.3.1. Trigger Syntax ..................................................................................................... 1697
18.3.2. Trigger Metadata .................................................................................................. 1700
18.4. Using Views ................................................................................................................... 1700
18.4.1. View Syntax ........................................................................................................ 1700
18.4.4. View Metadata ..................................................................................................... 1704
This chapter discusses stored programs and views, which are database objects defined in terms of
SQL code that is stored on the server for later execution.
Stored programs include these objects:
• Stored routines, that is, stored procedures and functions. A stored procedure is invoked using the
statement. A procedure does not have a return value but can modify its parameters for later
CALL
inspection by the caller. It can also generate result sets to be returned to the client program. A stored
function is used much like a built-in function. you invoke it in an expression and it returns a value
during expression evaluation.
• Triggers. A trigger is a named database object that is associated with a table and that is activated
when a particular event occurs for the table, such as an insert or update.
Views are stored queries that when referenced produce a result set. A view acts as a virtual table.
This chapter describes how to use stored programs and views. The following sections provide
additional information about SQL syntax for statements related to these objects:
• For each object type, there are CREATE, ALTER, and
exist and how they are defined. See
• The
CALL
• Stored program definitions include a body that may use compound statements, loops, conditionals,
and declared variables. See
18.1. Defining Stored Programs
Each stored program contains a body that consists of an SQL statement. This statement may be a
compound statement made up of several statements separated by semicolon (;) characters. For
example, the following stored procedure has a body made up of a
a
statement and a
SET
CREATE PROCEDURE dorepeat(p1 INT)
BEGIN
SET @x = 0;
REPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;
statement is used to invoke stored procedures. See
Section 13.6, "MySQL Compound-Statement
loop that itself contains another
REPEAT
statements that control which objects
DROP
Section 13.1, "Data Definition
1693
......................... 1697
Statements".
Section 13.2.1,
"CALL
Syntax".
block that contains
statement:
SET
Syntax".
Need help?
Do you have a question about the 5.0 and is the answer not in the manual?
Questions and answers