Browse Definitions :
Definition

Data Definition Language (DDL)

What is Data Definition Language (DDL)?

Data Definition Language (DDL) is used to create and modify the structure of objects in a database using predefined commands and a specific syntax. These database objects include tables, sequences, locations, aliases, schemas and indexes.

Data Definition Language explained

DDL is a standardized language with commands to define the storage groups (stogroups), different structures and objects in a database. DDL statements create, modify and remove database objects, such as tables, indexes and stogroups. DDL is also used in a generic sense to refer to any language that describes data.

DDL includes Structured Query Language (SQL) statements to create and drop databases, aliases, locations, indexes, tables and sequences. It also includes statements to alter these objects and impose or drop certain constraints on tables, such as the following:

  • UNIQUE
  • PRIMARY
  • FOREIGN KEY
  • CHECK

These constraints are used to enforce uniqueness, referential or domain integrity.

When a DDL statement is executed, it takes effect immediately in the database.

DDL is sometimes known as Data Description Language since its statements can also be used to describe, comment on and place labels on database objects.

DDL vs. SQL vs. DML vs. DQL

Since DDL includes SQL statements to define changes in the database schema, it is considered a subset of SQL. SQL uses normal English verbs to modify database objects, and DDL does not appear as a different language in a SQL database.

In Data Manipulation Language (DML), commands are used to modify data in a database. DML statements control access to the database data. In contrast, DDL commands are used to create, delete or alter the structure of objects in a database but not its data. DDL deals with descriptions of the database schema and is useful for creating new tables, indexes, sequences, stogroups, etc. and to define the attributes of these objects, such as data type, field length and alternate table names (aliases).

Structured Query Language (SQL) queries vs. Data Manipulation Language (DML) statements vs. Data Definition Language (DDL) commands
How Data Definition Language (DDL) commands, Data Manipulation Language (DML) statements and Structured Query Language (SQL) queries compare

Data Query Language (DQL) is used to get data within the schema objects of a database and also to query it and impose order upon it. Like DDL, DQL is also a subset of SQL. One of the most common commands in DQL is SELECT. It lets users get data from a database table and perform some operation on it. When the statement is executed, the result is compiled into a temporary table and displayed by the front-end program or application.

Common Data Definition Language commands

General application users -- i.e., users who are not authorized to work directly with a database -- do not use DDL commands. These general users can and should only access the database indirectly via the application.

The most common command types in DDL are CREATE, ALTER and DROP. All three types have a predefined syntax that must be followed for the command to run and changes to take effect.

1. CREATE

Syntax

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

The semicolon at the end of the command is used to process every command before it.

The CREATE group of DDL commands includes the following:

  • CREATE DATABASE defines a logical database under the active location root directory. The database normally consists of a subdirectory of the same name that holds the physical table and index files. Users can use stogroups to implicitly specify different storage directories for individual database objects.
  • CREATE TABLE creates a table by defining its columns and each column's data type and field length. The command can also be used to create primary and foreign keys for the table.
  • CREATE STOGROUP creates a Db2-style stogroup to define a physical directory area for storing database objects. A stogroup is associated with a specific directory path.
  • CREATE TABLESPACE creates a Db2-style tablespace to store tables from the same logical database in multiple directory paths. The tablespace is used with a stogroup.
  • CREATE ALIAS defines an alias for an existing table or view. The alias may be described in a different location as the table or view. This command also records the alias definition in the catalog tables at the current location.
  • CREATE SYNONYM can also be used to create an alternate name for an existing table or view at the current location.
  • CREATE INDEX creates an index on one or more columns of a table for faster data retrieval and to enforce uniqueness constraints on the columns.
  • CREATE LOCATION creates a new XDB server location in a user-specified subdirectory.
  • CREATE SEQUENCE must be used to create a sequence at the application server.
  • CREATE VIEW defines a virtual table that restricts data retrieval and updates to a subset of columns and rows from single- or multibase tables.
  • CREATE GLOBAL TEMPORARY can be used to create a temporary table's description at the current server.

2. DROP

DDL also includes several DROP commands to delete objects in a database. DROP commands cannot be undone, so once an object is deleted, it cannot be recovered.

Syntax

DROP object type object name;

The most common DROP commands are the following:

  • DROP DATABASE does the exact opposite of the CREATE DATABASE It deletes a database defined at a certain location, along with all the objects logically associated with it. It also deletes the database subdirectory even if it is empty and contains no objects logically associated with the database.
  • DROP STOGROUP deletes a stogroup by severing the logical connection between data objects defined using the stogroup and the directory path specified in the deleted stogroup definition. It doesn't delete the objects associated with the stogroup. As with other DROP commands, the DROP STOGROUP command should be used sparingly and with caution.
  • DROP TABLE deletes a database table and all associated indexes, views and synonyms built on it.
  • DROP TABLESPACE deletes a tablespace defined in the current location and all tables logically associated within it.
  • DROP ALIAS can be used to delete an alternate name for a table or view in a location's system catalog.
  • DROP SYNONYM can also be used to delete an alternate name for a table or view.
  • DROP INDEX deletes an index at the current location but only if the index was not created as the result of a UNIQUE, PRIMARY or FOREIGN KEY To drop/delete such indexes, the existing constraint must first be dropped with the ALTER command.
  • DROP LOCATION deletes a user-defined XDB server location and the catalog tables, directory structure and objects associated with it.
  • DROP VIEW deletes a view and all other views defined on it from the system catalog of the current location.

3. ALTER

The third group of DDL commands is ALTER. These commands are used to make modifications to database objects, such as indexes, locations and stogroups.

Syntax

ALTER object type object name parameters;

The most common ALTER commands are the following:

  • ALTER DATABASE modifies the information parameters of a database under the current XDB server location.
  • ALTER STOGROUP modifies the specifications of a stogroup defined at the current XDB server location.
  • ALTER TABLE adds, removes or alters columns and their data types. It can also enforce referential and domain integrity by creating or dropping UNIQUE, PRIMARY, FOREIGN KEY, and CHECK constraints in XDB mode. In Db2 mode, the command can also be used to enforce uniqueness constraints.
  • ALTER TABLESPACE changes the specifications of a tablespace within the current XDB server location.
  • ALTER VIEW uses an existing view definition at the current server to regenerate a view.
  • ALTER SEQUENCE changes sequence attributes at the current server.
  • ALTER INDEX modifies the configuration of an existing index. The XDB server syntactically supports the command to ensure compatibility with Db2.

4. Other commands

Apart from the CREATE, DROP and ALTER commands, DDL includes other commands:

  • COMMENT ON is used to add a single-line, multiline or inline comment about an object in the catalog tables at the current location.
  • LABEL ON is used to add or change descriptive text labels describing tables, views, aliases or columns to the catalog tables.
  • RENAME is used to modify the name of a database table.
  • TRUNCATE is used to quickly remove all records from a table, while preserving its full structure so it can be reused later.

Explore the difference between DDL and DML.

This was last updated in June 2022

Continue Reading About Data Definition Language (DDL)

Networking
  • subnet (subnetwork)

    A subnet, or subnetwork, is a segmented piece of a larger network. More specifically, subnets are a logical partition of an IP ...

  • secure access service edge (SASE)

    Secure access service edge (SASE), pronounced sassy, is a cloud architecture model that bundles together network and cloud-native...

  • Transmission Control Protocol (TCP)

    Transmission Control Protocol (TCP) is a standard protocol on the internet that ensures the reliable transmission of data between...

Security
  • cyber attack

    A cyber attack is any malicious attempt to gain unauthorized access to a computer, computing system or computer network with the ...

  • What is security information and event management (SIEM)?

    Security information and event management (SIEM) is an approach to security management that combines security information ...

  • digital signature

    A digital signature is a mathematical technique used to validate the authenticity and integrity of a digital document, message or...

CIO
  • product development (new product development)

    Product development -- also called new product management -- is a series of steps that includes the conceptualization, design, ...

  • innovation culture

    Innovation culture is the work environment that leaders cultivate to nurture unorthodox thinking and its application.

  • technology addiction

    Technology addiction is an impulse control disorder that involves the obsessive use of mobile devices, the internet or video ...

HRSoftware
  • organizational network analysis (ONA)

    Organizational network analysis (ONA) is a quantitative method for modeling and analyzing how communications, information, ...

  • HireVue

    HireVue is an enterprise video interviewing technology provider of a platform that lets recruiters and hiring managers screen ...

  • Human Resource Certification Institute (HRCI)

    Human Resource Certification Institute (HRCI) is a U.S.-based credentialing organization offering certifications to HR ...

Customer Experience
  • contact center agent (call center agent)

    A contact center agent is a person who handles incoming or outgoing customer communications for an organization.

  • contact center management

    Contact center management is the process of overseeing contact center operations with the goal of providing an outstanding ...

  • digital marketing

    Digital marketing is the promotion and marketing of goods and services to consumers through digital channels and electronic ...

Close