Documentation Home
MySQL 9.4 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 41.2Mb
PDF (A4) - 41.3Mb
Man Pages (TGZ) - 261.5Kb
Man Pages (Zip) - 368.4Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


MySQL 9.4 Reference Manual  /  Stored Objects

Chapter 27 Stored Objects

Table of Contents

27.1 Defining Stored Programs
27.2 Using Stored Routines
27.2.1 Stored Routine Syntax
27.2.2 Stored Routines and MySQL Privileges
27.2.3 Stored Routine Metadata
27.2.4 Stored Procedures, Functions, Triggers, and LAST_INSERT_ID()
27.3 JavaScript Stored Programs
27.3.1 JavaScript Stored Program Creation and Management
27.3.2 Obtaining Information About JavaScript Stored Programs
27.3.3 JavaScript Stored Program Language Support
27.3.4 JavaScript Stored Program Data Types and Argument Handling
27.3.5 JavaScript Stored Programs—Session Information and Options
27.3.6 JavaScript SQL API
27.3.7 Using the JavaScript SQL API
27.3.8 Using JavaScript Libraries
27.3.9 Using WebAssembly Libraries
27.3.10 JavaScript GenAI API
27.3.11 JavaScript Stored Program Limitations and Restrictions
27.3.12 JavaScript Stored Program Examples
27.4 Using Triggers
27.4.1 Trigger Syntax and Examples
27.4.2 Trigger Metadata
27.5 Using the Event Scheduler
27.5.1 Event Scheduler Overview
27.5.2 Event Scheduler Configuration
27.5.3 Event Syntax
27.5.4 Event Metadata
27.5.5 Event Scheduler Status
27.5.6 The Event Scheduler and MySQL Privileges
27.6 Using Views
27.6.1 View Syntax
27.6.2 View Processing Algorithms
27.6.3 Updatable and Insertable Views
27.6.4 The View WITH CHECK OPTION Clause
27.6.5 View Metadata
27.7 JSON Duality Views
27.7.1 JSON Duality View Syntax
27.7.2 Updatable JSON Duality Views (MySQL Enterprise Edition)
27.7.3 JSON Duality View Metadata
27.8 Stored Object Access Control
27.9 Stored Program Binary Logging
27.10 Restrictions on Stored Programs
27.11 Restrictions on Views

This chapter discusses stored database objects that are defined in terms of SQL code that is stored on the server for later execution.

Stored objects include these object types:

  • Stored procedure: An object created with CREATE PROCEDURE and invoked using the CALL statement. A procedure does not have a return value but can modify its parameters for later inspection by the caller. It can also generate result sets to be returned to the client program.

  • Stored function: An object created with CREATE FUNCTION and used much like a built-in function. You invoke it in an expression and it returns a value during expression evaluation.

  • Trigger: An object created with CREATE TRIGGER that is associated with a table. A trigger is activated when a particular event occurs for the table, such as an insert or update.

  • Event: An object created with CREATE EVENT and invoked by the server according to schedule.

  • View: An object created with CREATE VIEW that when referenced produces a result set. A view acts as a virtual table.

  • JSON Relational Duality View: An object created with CREATE JSON DUALITY VIEW that exposes selected columns of one or more tables as a JSON document. Also referred to as a JSON duality view, this object acts as a virtual JSON document.

Terminology used in this document reflects the stored object hierarchy:

  • Stored routines include stored procedures and functions.

  • Stored programs include stored routines, triggers, and events.

  • Stored objects include stored programs and views.

This chapter describes how to use stored objects. The following sections provide additional information about SQL syntax for statements related to these objects, and about object processing: