MENU
Data Definition Language
Data Definition Language (DDL) is the subset of SQL statements used to define, alter, and remove the structures that hold data: data types, tables, views, indexes, compound statements (stored procedures, functions, triggers, and events), and databases, servers, and plugins themselves. Unlike Data Manipulation Language, which reads and writes rows, DDL statements describe the shape of the schema.This chapter is organized into the following topics:
- Data Types – the numeric, string, date/time, spatial, and (MySQL 9.0+) vector column types MySQL supports.
- Table Definitions – CREATE TABLE, ALTER TABLE, RENAME TABLE, TRUNCATE/DROP TABLE, generated columns, tablespaces, compression, and encryption.
- Views – creating, altering, and dropping views, view algorithms, updatable views, and how views compare with temporary tables.
- Indexes – PRIMARY KEY, UNIQUE, INDEX, FOREIGN KEY, FULLTEXT, multi-value JSON indexes, invisible and descending indexes, generated invisible primary keys, and key caches.
- Compound Statements – stored procedures and functions in SQL or (MySQL 9.0+, Enterprise Edition) JavaScript, variable declarations, control-flow constructs, cursors, condition handlers, events, and triggers.
- Database, Server, Plugin – creating and dropping databases, defining remote servers for the FEDERATED engine, and installing plugins and components.
Together these statements let a schema designer declare every object a MySQL database can contain, from a single column's data type up to the routines and triggers that run inside the server.