Data definition language
A Data Definition Language (DDL) is a computer language for defining data structures.
XML Schema
XML Schema is an example of a pure DDL[citation needed] (although only relevant in the context of XML).
SQL
A subset of SQL's instructions form another DDL. These SQL statements define the structure of a database, including rows, columns, tables, indexes, and database specifics such as file locations. DDL SQL statements are more part of the DBMS and have large differences between the SQL variations. DDL SQL commands include the following:
CREATE statements
Create - To make a new database, table, index, or stored query.
A CREATE
statement in SQL creates an object inside of a relational database management system (RDBMS). The types of objects that can be created depends on which RDBMS is being used, but most support the creation TABLEs, INDEXes, USERs, and DATABASEs. Some systems (such as PostgreSQL) allow CREATE
, and other DDL commands, inside of a transaction and thus they may be rolled back.
CREATE TABLE
Perhaps the most common CREATE
command is the CREATE TABLE
command. The typical usage is:
CREATE [TEMP[ORARY]] TABLE [table name] ( [column definitions] ) [table parameters]
.
Column Definitions: A comma-separated list consisting of any of the following
- Column definition: [column name] [data type] {NULL | NOT NULL} {column options}
- Primary key definition: PRIMARY KEY ( [comma separated column list] )
- CONSTRAINTS: {CONSTRAINT} [constraint definition]
- RDBMS specific functionality
For example, the command to create a table named employees with a few sample columns would be:
CREATE TABLE employees (
id INTEGER PRIMARY KEY,
first_name CHAR(50) null,
last_name CHAR(75) not null,
date_of_birth DATE null
);
DROP statements
Drop - To destroy an existing database, table, index, or view.
A DROP
statement in SQL removes an object from a relational database management system (RDBMS). The types of objects that can be dropped depends on which RDBMS is being used, but most support the dropping of tables, users, and databases. Some systems (such as PostgreSQL) allow DROP and other DDL commands to occur inside of a transaction and thus be rolled back.
The typical usage is simply DROP objecttype objectname
. For example, the command to drop a table named employees would be:
DROP TABLE employees;
The DROP
statement is distinct from the DELETE
statement. For example, a DELETE
statement might delete some (or all) data from a table, whereas a DROP
statement might remove the entire table from the database.
ALTER statements
Alter - To modify an existing database object.
An ALTER
statement in SQL changes the properties of an object inside of a relational database management system (RDBMS). The types of objects that can be altered depends on which RDBMS is being used.
The typical usage is ALTER objecttype objectname parameters
. For example, the command to add a column named bubbles to an existing table named sink would be:
ALTER TABLE sink ADD bubbles INTEGER;