请输入您要查询的百科知识:

 

词条 Data definition language
释义

  1. History

  2. Structured query language (SQL)

     CREATE statement  CREATE TABLE statement  DROP statement  ALTER statement  TRUNCATE statement  Referential integrity statements 

  3. Other languages

  4. See also

  5. References

  6. External links

{{short description|Syntax for defining data structures}}{{Distinguish|Data manipulation language}}{{Refimprove|date=December 2012}}

A data definition or data description language (DDL) is a syntax similar to a computer programming language for defining data structures, especially database schemas. DDL statements create, modify, and remove database objects such as tables, indexes, and users. Common DDL statements are CREATE, ALTER, and DROP

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 was written in a language syntax describing the records, fields, and sets of the user data model.[1] 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[2]. These information tables were specified as SQL/Schemata in 2003. The term DDL is also used in a generic sense to refer to any formal language 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 (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[2]. 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.[3][4]

CREATE TABLE statement

A commonly used CREATE command is the CREATE TABLE command. The typical usage is:

The column definitions are:

  • 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

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,    fname         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.[5]

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:

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 (RDBMS). The types of objects that can be altered depends on which RDBMS is being used. The typical usage is:

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 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 is an example of a DDL for XML.

See also

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

References

1. ^{{cite book|last=Olle|first=T. William|title=The Codasyl Approach to Data Base Management|year=1978|publisher=Wiley|isbn=0-471-99579-7}}
2. ^{{cite web |title=Information Technology - Database Language SQL |url=http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt |website=SQL92 |publisher=Carnegie Mellon |accessdate=12 November 2018}}
3. ^{{cite web |last1=Laudenschlager |first1=Douglas |last2=Milener |first2=Gene |last3=Guyer |first3=Craig |last4=Byham |first4=Rick |title=Transactions (Transact-SQL) |url=https://docs.microsoft.com/en-us/sql/t-sql/language-elements/transactions-transact-sql?view=sql-server-2017 |website=Microsoft Docs |publisher=Microsoft |accessdate=12 November 2018}}
4. ^{{cite web |title=PostgreSQL Transactions |url=https://www.postgresql.org/docs/8.3/tutorial-transactions.html |website=PostgreSQL 8.3 Documentation |publisher=PostgreSQL |accessdate=12 November 2018}}
5. ^{{cite book| last = Allen| first = Grant| others = Mike Owens| title = The Definitive Guide to SQLite| url = https://books.google.com/books?id=WLinoJaOUCwC| accessdate = 2012-10-02| edition = 2| series = Apresspod| year = 2010| publisher = Apress| isbn = 9781430232254| pages = 90–91| quote = The create table statement has a special syntax for creating tables from select statements. [...]: [...] create table foods2 as select * from foods; [...] Many other databases refer to this approach as CTAS, which stands for Create Table As Select, and that phrase is not uncommon among SQLite users.}}

External links

  • [https://oracletutorial.net/alter-table-modify-column-oracle.html Oracle ALTER TABLE MODIFY column]
  • [https://oracletutorial.net/dml-ddl-commands-in-oracle.html#ddl-commands-in-oracle DDL Commands In Oracle]
{{Database}}{{databases}}

3 : Articles with example SQL code|Data modeling languages|SQL

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/10 20:35:38