Data Definition Language (DDL) in MySQL
Data Definition Language (DDL) forms a core subset of SQL commands used to create, modify, and manage database structures. Unlike manipulation statements which handle actual records, DDL changes the fundamental schema of database objects. Here is a definitive practical guide to the fundamental core operations: CREATE, DROP, and ALTER.
Establishes entirely new structures such as physical database directories or target relation tables.
Modifies structural properties, modifying constraints, data attributes, or individual columns.
Destroys structural components and configurations completely from system indices.
1. CREATE DATABASE
The CREATE DATABASE statement generates a new physical directory file container under your relational server setup instance.
Syntax Structure
Practical Example
2. CREATE TABLE
The CREATE TABLE command builds structured tracking matrix relations inside active environments, requiring explicitly outlined column schemas, relational configurations, and specific target data types.
Syntax Structure
column1 datatype constraints,
column2 datatype constraints,
...
);
Practical Example
StudentID INT PRIMARY KEY AUTO_INCREMENT,
Name VARCHAR(100) NOT NULL,
Age INT,
EnrollmentDate DATE
);
3. DROP
The DROP routine is an absolute administrative tool that destroys architectural entities. Executing a drop query drops tracking indices alongside all historical datasets contained inside structures.
Syntax Options
DROP DATABASE database_name;
-- To remove an individual database table layout
DROP TABLE table_name;
Practical Examples
DROP DATABASE SchoolDB;
4. ALTER TABLE
The ALTER TABLE framework alters column configurations inside existing datasets without needing a complete operational drop sequence.
4.1 Add Column
Appends a fresh structural column property onto an existing layout layer:
/* Example: */
ALTER TABLE Students ADD Email VARCHAR(100);
4.2 Modify Column Type
Changes the attribute properties or allocation parameters of an existing data column:
/* Example: */
ALTER TABLE Students MODIFY Age TINYINT;
4.3 Drop Single Column
Isolates and drops a specific attribute column along with all mapped records contained inside its vertical path:
/* Example: */
ALTER TABLE Students DROP COLUMN EnrollmentDate;
4.4 Rename Table Mapping
Changes the access path reference mapping alias properties on any designated object:
/* Example: */
ALTER TABLE Students RENAME TO Pupils;
4.5 Rename Column Properties
Changes a column name while simultaneously redefining or maintaining its target database mapping types:
/* Example: */
ALTER TABLE Students CHANGE Name FullName VARCHAR(100);
Core DDL Summary Table
To summarize, keep this quick architectural reference logic checklist handy:
- CREATE DATABASE: Generates separate backend file storage pathways.
- CREATE TABLE: Builds logical tabular tracking grids inside targets.
- DROP: Permanently deletes operational components and metrics.
- ALTER: Adds, structuralizes, or completely updates layout columns.
.png)
.png)