ITP

BSc IT - Database Management System

Explain syntax and use of DDL ststements.

In : BSc IT Subject : Database Management System

DDL stands for Data Definition Language.

These are SQL commands used to define or change the structure of a database. They help you create, modify, or delete database objects like tables, indexes, and schemas.

## Common DDL Commands with Syntax and Use

CREATE -  `CREATE TABLE table_name (column1 datatype, column2 datatype, ...);` - Used to create a new database object, like a table. <br> Example: Creating a `Students` table. 
ALTER   -  `ALTER TABLE table_name ADD column_name datatype;` - Used to modify an existing table structure, like adding or removing a column. 
DROP    -  `DROP TABLE table_name;` - Used to delete an entire table or database object, including all its data and structure.
TRUNCATE - `TRUNCATE TABLE table_name;` - Used to remove all records from a table quickly, but keeps the table structure. (Faster than `DELETE`) 
RENAME    - `RENAME TABLE old_name TO new_name;` - Used to rename a table or other database object.

##Example: Using DDL Commands

-- 1. CREATE a table
CREATE TABLE Students (
    StudentID INT,
    Name VARCHAR(50),
    Age INT
);

-- 2. ALTER the table to add a column
ALTER TABLE Students ADD Email VARCHAR(100);

-- 3. TRUNCATE the table (remove all data)
TRUNCATE TABLE Students;

-- 4. DROP the table (remove table structure)
DROP TABLE Students;


About us

A truly open platform where you may ask questions and get answers. We also provide comprehensive and easy-to-understand answers to question papers.  discover...

Site status

Flag Counter

Privacy Policy

Sitemap