CREATE DATABASE, CREATE TABLE, DROP, ALTER notes| DDL

 

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.

1 CREATE

Establishes entirely new structures such as physical database directories or target relation tables.

2 ALTER

Modifies structural properties, modifying constraints, data attributes, or individual columns.

3 DROP

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

CREATE DATABASE database_name;

Practical Example

CREATE DATABASE SchoolDB;

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

CREATE TABLE table_name (
    column1 datatype constraints,
    column2 datatype constraints,
    ...
);

Practical Example

CREATE TABLE Students (
    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.

CRITICAL SAFETY WARNING: DROP runs instantly without a confirmation prompt. Executing this statement completely and permanently removes the component along with its entire record collection. Recovery is impossible without complete server backup files.

Syntax Options

-- To remove an entire database container
DROP DATABASE database_name;

-- To remove an individual database table layout
DROP TABLE table_name;

Practical Examples

DROP TABLE Students;
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:

ALTER TABLE table_name ADD column_name datatype;
/* 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:

ALTER TABLE table_name MODIFY column_name new_datatype;
/* 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:

ALTER TABLE table_name DROP COLUMN column_name;
/* Example: */
ALTER TABLE Students DROP COLUMN EnrollmentDate;

4.4 Rename Table Mapping

Changes the access path reference mapping alias properties on any designated object:

ALTER TABLE old_table_name RENAME TO new_table_name;
/* 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:

ALTER TABLE table_name CHANGE old_column_name new_column_name new_datatype;
/* 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.

Post a Comment

Please do note create link post in comment section

Previous Post Next Post