DDL (Data Definition Language)

It is used to define the structure of the database schema, including creating, altering, and dropping schema objects like tables, views, indexes, and users.

DDL does not include creating the database itself in oracle context. DDL commands are specifically used to define the structure of objects within an existing database. It is included in some database management systems (DBMS), such as MySQL and PostgreSQL.

CREATE

Creates a new database object.

  • Syntax

CREATE [schema_name.]object_type [object_name] ([object_definition]);
  • Example

CREATE TABLE Customers (
  CustomerID NUMBER PRIMARY KEY,
  CustomerName VARCHAR2(50) NOT NULL,
  Email VARCHAR2(100) UNIQUE,
  Phone VARCHAR2(20)
);

ALTER

Modifies the structure of an existing database object.

  • Syntax

  • Example

DROP

Removes a database object from the schema.

  • Syntax

  • Example

TRUNCATE

Removes all rows from a table, but preserves the table structure. This is a faster alternative to DROP and then CREATE, but cannot be rolled back.

  • Syntax

  • Example

COMMENT

Adds a comment to a database object to provide descriptive information

  • Syntax

  • Example

RENAME

Renames a database object.

  • Syntax

  • Example

Last updated