DDL

Basic SQL
≈ 1 min read

DDL changes database structure

DDL — Data Definition Language — groups statements that work with database structure. They create tables and other objects, change their definitions, or remove them.

CREATE TABLE users (
    id INTEGER,
    name VARCHAR(100)
);

CREATE TABLE creates a new table and lists its columns. For now, we specify only names and types; integrity rules for columns are covered separately.

ALTER and DROP

When the structure of an existing table needs to change, ALTER TABLE is used. For example, a new column can be added:

ALTER TABLE users
ADD COLUMN email VARCHAR(200);

The DROP TABLE statement removes the table as a database object. This changes the schema rather than deleting individual rows.

DDL statements can be destructive. Changing or removing structure can affect existing data. Before running such statements, make sure you understand which object is being changed and whether the data can be safely recovered.