Structured Query language DDL Commands

lets explore the Data Definition Language commands in SQL

Feb 2, 2025

·

10

min read

Structured Query language DDL Commands

Data Definition Language commands in SQL are used to define the structure of the Database.There is a fixed syntax for describing the data.These commands helps organizing the data in the Database.

There are five commands which fall under this category:

  1. CREATE

  2. DROP

  3. ALTER

  4. TRUNCATE

  5. RENAME

lets see each command one by one.

  1. CREATE

CREATE is used to databse objects whether they are tables , schemas and indexex.

Creating a Databse

CREATE DATABASE college;

it will create a database named college;

Creating a table inside college databse

CREATE TABLE college.students (

id INT PRIMARY KEY,

name VARCHAR(50),

age INT

);

This command will create students table inside college database.

  1. DROP

DROP command delete the entire object permanently. The database or table will not be present after that.

Dropping a table

DROP TABLE college.students;


Dropping the Database

DROP DATABSE collge;


  1. ALTER

ALTER is used to modify existing databse tables i.e (adding or deleting columns in a table).

ALTER TABLE college.students ADD COLUMN email VARCHAR(100);

it will add email column in students table.

  1. TRUNCATE

TRUNCATE remove the data from the table , but it keeps the structure i.e we do not have to create table again we just have to insert data into it.

TRUNCATE TABLE college.students;

After this command all the records from student table will be deleted.

  1. RENAME

This RENAME command is used to rename the table.

RENAME TABLE students TO allstudents;



Next up

I’m Safdar — a web developer and machine learning enthusiast based in India.

I’m Safdar — a web developer and machine learning enthusiast based in India.

I’m Safdar — a web developer and machine learning enthusiast based in India.