The Wayback Machine - https://web.archive.org/web/20240813220318/https://www.geeksforgeeks.org/ddl-commands-syntax/
Open In App

DDL Commands & Syntax

Last Updated : 03 Apr, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In this article, we will discuss the overview of DDL commands and will understand DDL commands like create, alter, truncate, drop. We will cover each command syntax with the help of an example for better understanding. Let’s discuss it one by one.

Overview :
Data Definition Language(DDL) is a subset of SQL and a part of DBMS(Database Management System). DDL consist of Commands to commands like CREATE, ALTER, TRUNCATE and DROP. These commands are used to create or modify the tables in SQL.

DDL Commands :
In this section, We will cover the following DDL commands as follows.

  1. Create
  2. Alter 
  3. truncate
  4. drop
  5. Rename 

Let’s discuss it one by one.

Command-1 :
CREATE :
This command is used to create a new table in SQL. The user has to give information like table name, column names, and their datatypes.

Syntax –

CREATE TABLE table_name
(
column_1 datatype,
column_2 datatype,
column_3 datatype,
....
);

Example –
We need to create a table for storing Student information of a particular College. Create syntax would be as below.

CREATE TABLE Student_info
(
College_Id number(2),
College_name varchar(30),
Branch varchar(10)
);

Command-2 :
ALTER :
This command is used to add, delete or change columns in the existing table. The user needs to know the existing table name and can do add, delete or modify tasks easily.

Syntax –
Syntax to add a column to an existing table.

ALTER TABLE table_name
ADD column_name datatype;

Example –
In our Student_info table, we want to add a new column for CGPA. The syntax would be as below as follows.

ALTER TABLE Student_info
ADD CGPA number;

Command-3 :
TRUNCATE :
This command is used to remove all rows from the table, but the structure of the table still exists.

Syntax –
Syntax to remove an existing table.

TRUNCATE TABLE table_name;

Example –
The College Authority wants to remove the details of all students for new batches but wants to keep the table structure. The command they can use is as follows.

TRUNCATE TABLE Student_info;

Command-4 :
DROP :
This command is used to remove an existing table along with its structure from the Database.

Syntax –
Syntax to drop an existing table.

DROP TABLE table_name;

Example –
If the College Authority wants to change their Database by deleting the Student_info Table. 

DROP TABLE Student_info;

Command -5

RENAME:

It is possible to change name of table with or without data in it using simple RENAME command.

We can rename any table object at any point of time.

Syntax –

RENAME TABLE <Table Name> To <New_Table_Name>;

Example:

If you want to change the name of the table from Employee to Emp we can use rename command as 

RENAME TABLE Employee To EMP;


Similar Reads

SQL Commands | DDL, DQL, DML, DCL and TCL Commands
SQL commands are very used to interact with the database. These commands allow users to perform various actions on a database. This article will teach us about SQL commands or SQL sublanguage commands like DDL, DQL, DML, DCL, and TCL. All important SQL commands with their syntax and examples are covered in this article. But before heading to the SQ
6 min read
DDL Full Form
DDL stands for Data Definition Language. These commands are used to change the structure of a database and database objects.For example, DDL commands can be used to add, remove, or modify tables with in a database.The DDL commands are: CREATEALTERDROPTRUNCATERENAME 1. CREATE : This command is used to create table in the relational database . This c
4 min read
Difference between DDL and TCL
Prerequisite – SQL Commands 1 Data Definition Language (DDL) is a set of SQL (Structured Query Language) commands used to create, modify, and delete database objects such as tables, indexes, views, and constraints. DDL statements are used to define the schema or structure of a database, including its data types, relationships between tables, and ru
2 min read
Difference Between DDL and DML in DBMS
DDL is a Data Definition Language that is used to define data structures. For example: creating a table, and altering a table are instructions in SQL. DML is a Data Manipulation Language that is used to manipulate data itself. For example: insert, update, and delete are instructions in SQL. Data Definition Language DDL is used to specify a database
3 min read
SQL | DDL, DML, TCL and DCL
Data Definition Language (DDL), Data Manipulation Language (DML), Transaction Control Language (TCL), and Data Control Language (DCL) form the backbone of SQL. Each of these languages plays a critical role in defining, managing, and controlling data within a database system, ensuring both structural integrity and user access control. In this articl
6 min read
Adding &amp; Editing &amp; Deleting &amp; Searching Records with Data Form
Overview :To manage records using Data Form, it will give you the following options like adding data, deleting data, searching data using data from. Let's discuss Adding, Deleting, Searching Records with Data Form as follows. Steps to implement operations with data form :Here, we will discuss how you can add, delete and search data using data form
4 min read
SQLite Statements and Syntax
SQLite is a self-contained, file-based SQL database that follows a specific syntax. Statements in SQLite are used to query the database and are essential for database management. Every statement follows a fixed syntax in SQLite. In this guide, we will look at some important SQLite statements and syntaxes. We have divided the statements into several
3 min read
SQL Syntax
Structured Query Language (SQL) is a standardized Query language essential for managing and manipulating relational databases. Mastery of SQL syntax is crucial for writing effective SQL queries and ensuring proper interaction with database management systems (DBMS). This guide will provide a thorough understanding of SQL syntax, enhancing clarity a
3 min read
Useful and time saving bash commands in Linux
There are many useful bash scripts that can make things easier. Many things can be done just using the terminal. Here is a list of some of such useful bash scripts through which we can do things that cannot be done manually. 1. Counting the number of files(or directory) in a given directory: Go to the directory in which you want to count the number
3 min read
halt, poweroff and reboot Commands in Linux
Below are typical uses of halt, poweroff and reboot. halt : Instructs hardware to stop CPU functions. poweroff : Instructs the system to power down. reboot : Restarts or reboots the system. The above mentioned commands can only be run by super user as these involve the actions to stop the system hardware. If the user is not logged in as super user
2 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg