Data Definition Language (DDL)

A Data Definition Language (DDL) or Data Description is a programming language used to construct and change the database object structure within a database. DDL is a syntax for creating and modifying objects from databases, such as tables, indexes, and users. For example, DDL commands may be used in a database to add, delete, or change tables.

The DDL commands are:

  • CREATE
  • ALTER
  • DROP
  • TRUNCATE
  • RENAME

First introduced the idea of the data structure language and its name in relation to the Codasyl database model, where the database schema was written in a language syntax describing the user data model documents, fields, and sets. However, it’s considered to be a subset of SQL (Structured Query Language). SQL often uses imperative verbs with normal English like sentences to implement database modifications. The term DDL is additionally utilized in a generic sense to discuss with any formal language for describing data or information structures.

Therefore DDL does not appear in a SQL database as a separate language but describes changes in the database schema. However, SQL uses a set of imperative verbs whose effect is to change the database schema by inserting, modifying, or removing tables or other element meanings. These statements can be freely mixed with other SQL statements, making the DDL, not a separate language.

Commonly used DDL in SQL querying are:

CREATE: Use the create command to construct a new database, table, index, or stored procedure. The CREATE statement syntax is CREATE TABLE [table name] ([column definitions]) [table parameters]. This command is used to create a table in the relational database.

ALTER:

Alter command is used for altering the table in many forms like:

Add a column

Rename existing column

Drop a column

Modify the size of the column or change datatype of the column

An ALTER statement in the SQL changes the properties of an object within a relational database management (RDBMS) framework. The types of artifacts to modify depend on the RDBMS is being used. The typical usage is: ALTER objecttype objectname parameters.

DROP: A SQL DROP statement removes a portion from Relational Database Management (RDBMS) framework. The terminology for the drop statement is the name of an object type DROP. Staff DROP TABLE. Some systems (such as PostgreSQL) allow the inside of a transaction to occur DROP and other DDL commands and thus be rolled back. The typical usage is simply: DROP objecttype objectname.

TRUNCATE: The declaration TRUNCATE is used to delete all data from a row. This is much quicker than DELETE. But this order will not ruin the structure of the table. TRUNCATE TABLE table_name.

RENAME:

Syntax to rename column:

ALTER TABLE

table_name

RENAME

old_column_name TO new_column_name;

Another form of DDL sentence in SQL is used to identify relationships of referential integrity, typically implemented in certain columns of tables as primary key and foreign key tags. These two statements can be included in a CREATE TABLE or an ALTER TABLE sentence.

 

Information Sources:

  1. techopedia.com
  2. geeksforgeeks.org
  3. wikipedia