HOME

TheInfoList



OR:

In the context of SQL, data definition or data description language (DDL) is a syntax for creating and modifying database objects such as tables, indices, and users. DDL statements are similar to a computer
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
for defining
data structure In computer science, a data structure is a data organization and storage format that is usually chosen for Efficiency, efficient Data access, access to data. More precisely, a data structure is a collection of data values, the relationships amo ...
s, especially
database schema The database schema is the structure of a database described in a formal language supported typically by a relational database management system (RDBMS). The term "wikt:schema, schema" refers to the organization of data as a blueprint of how the ...
s. Common examples of DDL statements include CREATE, ALTER, and DROP. If you see a .ddl file, that means the file contains a statement to create a table. Oracle SQL Developer contains the ability to export from an ERD generated with Data Modeler to either a .sql file or a .ddl file.


History

The concept of the data definition language and its name was first introduced in relation to the Codasyl database model, where the schema of the
database In computing, a database is an organized collection of data or a type of data store based on the use of a database management system (DBMS), the software that interacts with end users, applications, and the database itself to capture and a ...
was written in a language syntax describing the records, fields, and sets of the user data model. Later it was used to refer to a subset of Structured Query Language (SQL) for declaring tables, columns, data types and constraints. SQL-92 introduced a schema manipulation language and schema information tables to query schemas. These information tables were specified as SQL/Schemata in SQL:2003. The term DDL is also used in a generic sense to refer to any
formal language In logic, mathematics, computer science, and linguistics, a formal language is a set of strings whose symbols are taken from a set called "alphabet". The alphabet of a formal language consists of symbols that concatenate into strings (also c ...
for describing data or information structures.


Structured Query Language (SQL)

Many data description languages use a declarative syntax to define columns and data types. Structured Query Language (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 A stored procedure (also termed prc, proc, storp, sproc, StoPro, StoredProc, StoreProc, sp, or SP) is a subroutine available to applications that access a relational database management system (RDBMS). Such procedures are stored in the database d ...
. The ''CREATE'' statement in SQL creates a component in a
relational database management system A relational database (RDB) is a database based on the relational model of data, as proposed by E. F. Codd in 1970. A Relational Database Management System (RDBMS) is a type of database management system that stores data in a structured for ...
(RDBMS). In the SQL 1992 specification, the types of components that can be created are schemas, tables, views, domains,
character set Character encoding is the process of assigning numbers to graphical characters, especially the written characters of human language, allowing them to be stored, transmitted, and transformed using computers. The numerical values that make up a c ...
s, collations, translations, and assertions. Many implementations extend the syntax to allow creation of additional elements, such as
indexes Index (: indexes or indices) may refer to: Arts, entertainment, and media Fictional entities * Index (A Certain Magical Index), Index (''A Certain Magical Index''), a character in the light novel series ''A Certain Magical Index'' * The Index, a ...
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 ''CREATE TABLE'' command. The typical usage is: CREATE TABLE '' able name' ( '' olumn definitions' ) '' able parameters' The column definitions are: *A comma-separated list consisting of any of the following *Column definition: '' olumn name' '' ata type' ' ' * Primary key definition: ''PRIMARY KEY'' ( '' omma separated column list' ) *Constraints: ' '' onstraint definition' * RDBMS specific functionality An example statement to create a table named ''employees'' with a few columns is: CREATE TABLE employees ( id INTEGER PRIMARY KEY, first_name VARCHAR(50) not null, last_name VARCHAR(75) not null, mid_name VARCHAR(50) not null, dateofbirth DATE not null ); 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 A relational database (RDB) is a database based on the relational model of data, as proposed by E. F. Codd in 1970. A Relational Database Management System (RDBMS) is a type of database management system that stores data in a structured for ...
(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
database In computing, a database is an organized collection of data or a type of data store based on the use of a database management system (DBMS), the software that interacts with end users, applications, and the database itself to capture and a ...
s. 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 is: DROP TABLE employees; 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 A relational database (RDB) is a database based on the relational model of data, as proposed by E. F. Codd in 1970. A Relational Database Management System (RDBMS) is a type of database management system that stores data in a structured for ...
(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 (then remove) a column named bubbles for an existing table named sink is: ALTER TABLE sink ADD bubbles INTEGER; ALTER TABLE sink DROP COLUMN bubbles;


TRUNCATE statement

The ''TRUNCATE'' statement is used to delete all data from a table. It's much faster than ''DELETE''. TRUNCATE TABLE table_name;


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 A foreign key is a set of attributes in a table that refers to the primary key of another table, linking these two tables. In the context of relational databases, a foreign key is subject to an inclusion dependency constraint that the tuples ...
tags in some columns of the tables. These two statements can be included in a ''CREATE TABLE'' or an ''ALTER TABLE'' sentence;


Other languages

*
XML Schema An XML schema is a description of a type of XML document, typically expressed in terms of constraints on the structure and content of documents of that type, above and beyond the basic syntactical constraints imposed by XML itself. These constrai ...
is an example of a DDL for
XML Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
. * JSON Schema is an example of a DDL for
JSON JSON (JavaScript Object Notation, pronounced or ) is an open standard file format and electronic data interchange, data interchange format that uses Human-readable medium and data, human-readable text to store and transmit data objects consi ...
. * DFDL schema is an example of a DDL that can describe many text and binary formats.


See also

* Data control language * Data manipulation language * Data query language * Select (SQL) * Insert (SQL) * Update (SQL) * Delete (SQL) * Truncate (SQL)


References


External links


Oracle ALTER TABLE MODIFY column


{{Database Articles with example SQL code Data modeling languages SQL