ArticleslgStudy

science

Data definition language

Data definition language is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Data definition language rather than just read about it. In short: In the context of SQL, data definition 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 for defining data structures, especially database schemas.

Data definition language — main illustration
Data definition language — illustration

Key takeaways

  • Data definition language belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Data definition language to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Data definition language from memory before moving on to harder problems.

Reference excerpt

In the context of SQL, data definition 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 for defining data structures, especially database schemas. 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 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 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. 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 CREATE TABLE command. The typical usage is:

CREATE TABLE [table name] ( [column definitions] ) [table parameters]

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:

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:

DROP objecttype objectname.

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. 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:

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

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. JSON Schema is an example of a DDL for JSON. 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 Archived 2021-04-21 at the Wayback Machine DDL Commands In Oracle Archived 2021-04-21 at the Wayback Machine

Illustrations

Data definition language: Saving a ddl file in Oracle SQL Developer
Saving a ddl file in Oracle SQL Developer

Worked examples

Example 1 — a first encounter with Data definition language

Start with the simplest possible case. Write down what Data definition language claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Data definition language before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Data definition language ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Data definition language

In research
Data definition language appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Data definition language in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Data definition language is common in secondary-school and first-year university syllabi. It links to neighbouring topics Data modeling languages, SQL, so understanding it makes those chapters shorter.
In everyday life
Look for Data definition language outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Data definition language” →

How to study Data definition language in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Data definition language means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Data definition language out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Data definition language in simple terms?

In the context of SQL, data definition 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 for defining data structures, especially database schemas.

Why does Data definition language matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Data definition language?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Data definition language.

Tags

  • Data modeling languages
  • SQL

Keep exploring