Data definition language
A data definition language or
data description language
(DDL) is a syntax similar to a computer programming
language for defining
data structures, especially
database schemas.
Many data description languages use a declarative syntax to define columns and data types. Structured query language (e.g., SQL), however, uses a collection of imperative verbs whose effect is to modify the schema of the database by adding, changing, or deleting definitions of tables or other elements. These statements can be freely mixed with other SQL statements, making the DDL not a separate language.
CREATE statement
The create command is used to establish a new database, table, index, or stored procedure.
The CREATE statement in SQL creates a component in a relational database management system (RDBMS). In the SQL 1992 specification, the types of components that can be created are schemas, tables, views, domains, character sets, collations, translations, and assertions. Many implementations extend the syntax to allow creation of additional elements, such as indexes and user profiles. Some systems, such as PostgreSQL and SQL Server, allow CREATE, and other DDL commands, inside a database transaction and thus they may be rolled back.
CREATE TABLE statement
A commonly used CREATE command is the CRE
The column definitions are:
- A comma-separated list consisting of any of the following
- Column definitiona
- Primary key definition: PRIMARY KEY
- Constraints:
- RDBMS specific functionality
An example statement to create a table named employees with a few
Some forms of CREATE TABLE DDL may incorporate DML (data manipulation language)-like constructs, such as the CREATE TABLE AS SELECT (CTAS) syntax of SQL.
DROP statement
The DROP statement destroys an existing database, table, index, or view.
A DROP statement in SQL removes a component 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:
For example, the command to drop a table named employees is:
The DROP statement is distinct from the DELETE and TRUNCATE statements, in that DELETE and TRUNCATE do not remove the table itself. For example, a DELETE statement might delete some (or all) data from a table while leaving the table itself in the database, whereas a DROP statement removes the entire table from the database.
ALTER statement
The ALTER statement modifies 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.
For example, the command to add (then remove) a column named bubbles for an existing table named sink is:
RENAME statement
The RENAME statement is used to rename a database.
TRUNCATE statement
The TRUNCATE statement is used to delete all data from a table.
Referential integrity statements
Another type of DDL sentence in SQL is used to define referential integrity relationships, usually implemented as primary key and foreign key tags in some columns of the tables. These two statements can be included in a CREATE TABLE or an ALTER TABLE sentence.
Comments
Post a Comment
8368456574