Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests -

Data Definition Language

A Data Definition Language (DDL) refers to a language that is used to modify data and define data structures. For instance, the DDL commands could be used to remove, add, or modify tables within a database. The DDLs used in DB applications are considered to be a subset of the Structured Query Language.

In this article, we will take a look at the Data Definition Language according to the GATE Syllabus for CSE (Computer Science Engineering). Read ahead to learn more.

Table of Contents

What is Data Definition Language?

DDL is used as an abbreviation for Data Definition Language. DDL refers to a computer language that is primarily used for creating as well as modifying the structure of the database objects present in a database. Such database objects include indexes, tables, schemas, views, and many more.

DDL is also referred to as a data description language in certain contexts since it describes the records and fields in the DB (database) tables.

More on Data Definition Language (DDL)

The current database industry basically incorporates DDL into the formal language that describes data. However, DDL is often considered a subset of Structured Query Language or SQL. Now, SQL often makes use of imperative verbs, along with normal English (like sentences) in order to implement database modifications. Thus, DDL doesn’t really show up to be a different language in the database of SQL, but it does define all the changes present in the DB schema.

It is mainly used to modify and establish the structure of the objects present in a database by dealing with the database schema descriptions. Unlike DML (data manipulation language) commands that we use for data modification, DDL commands are actually used to alter the structure of the database, like creating new objects or tables along with their attributes (table name, data type, etc.).

CREATE, DROP, ALTER, and TRUNCATE are commonly used in Data Definition Languages in SQL querying. Let’s discuss these in detail.

Create

The CREATE command builds a new table. It has a predefined syntax, and the CREATE statement syntax goes like this:

CREATE TABLE [name_of_table] ([definitions_of_column]) [parameters_of_table];

For instance,

CREATE TABLE Student (Student Id INTEGER PRIMARY KEY, Name CHAR (50) NULL, Nickname CHAR (75) NOT NULL);

Here, the semi-colon used at the end of the statement is mandatory, and it is used to process every command before it. So, in the example mentioned above, we are trying to specify the data type using the string CHAR. Visit to learn more about the CREATE statement here. Various other data types are NUMBER, INTEGER or DATE.

Alter

The alter command modifies any existing table in a database. The Alter command can add up an additional column, drop the existing columns and even change the data types of various columns involved in a DB table. Read more on the ALTER command here.

The syntax of an ALTER command is:

ALTER type_of_object name_of_object parameters;

For instance,

ALTER TABLE Student ADD PRIMARY KEY (student_pk);

In this example, we have added the unique primary key to this table. It adds a constraint and enforces a unique value. Here, the constraint “student_pk” is the primary key, and it is on the Student table.

Drop

The DROP command is used in order to delete objects, like a table, view or index. We cannot rollback the DROP statement. Thus, once a certain object is destroyed, there would be no way at all to recover it.

The syntax of the DROP statement is:

DROP type_of_object name_of_object;

For instance,

DROP TABLE Student;

We have deleted the Employee table in this example.

Truncate

Just like the DROP statement, the TRUNCATE statement is mainly used to remove all the records from a table quickly. However, unlike the DROP statement that destroys a table completely, the TRUNCATE statement preserves the full structure so as to be reused later.

The syntax of the TRUNCATE statement is:

TRUNCATE TABLE name_of_table;

For instance,

TRUNCATE TABLE Student;

In the example given here, we have marked all the extents in the Employee table for deallocation. This way, they are considered empty for us to reuse.

Other Statements

There are some other commonly used commands. These include RENAME and COMMENT. The RENAME statement is used along with the ALTER TABLE statement in order to change an object’s name (the object can be a table, column, etc.). On the other hand, the COMMENT statement is used when we want to add various single-line, in-line and multi-line comments.

Keep learning and stay tuned to get the latest updates on GATE Exam along with GATE Eligibility CriteriaGATE 2023GATE Admit CardGATE SyllabusGATE Previous Year Question Paper, and more.

Also Explore,

Comments

Leave a Comment

Your Mobile number and Email id will not be published.

*

*