What are the DDL commands in DBMS?


Data definition language (DDL) is a language that allows the user to define the data and their relationship to other types of data.

Data Definition language statements work with the structure of the database table.

  • Various data types used in defining columns in a database table

  • Integrity and value constraints

  • Viewing, modifying and removing a table structure

DDL Commands

The Data Definition Languages (DDL) Commands are as follows −

  • Create − It is used to create a new table or a new database.

  • Alter − It is used to alter or change the structure of the database table.

  • Drop − It is used to delete a table, index, or views from the database.

  • Truncate − It is used to delete the records or data from the table, but its structure remains as it is.

  • Rename − It is used to rename an object from the database.

When you create a table, you have to specify the following −

  • Table name.

  • Name of each column.

  • Data type of each column.

  • Size of each column.

Data types

When a table is created, each column in the table is assigned a data type.

Some of the important data types are as follows −

  • Varchar2

  • Char

  • Number

DDL Commands with example

Let’s see each DDL command with an example.

Create

It is used to create a new table or a new database.

An example of the create command is as follows −

create table student(stdname varchar(20) , branch varchar(20),college varchar(20), age number, telephone number, address varchar(20));

A student table is created with the fields given below −

Stdname
Branch
College
Age
Telephone
Address


















Alter

It is used to alter or change the structure of the database table

An example of the alter command is as follows −

ALTER TABLE student ADD birthdate DATETIME

Drop

It is used to delete a table, index, or views from the database.

An example of the drop command is as follows −

 DROP TABLE student

Updated on: 03-Jul-2021

12K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements