Ddl Commands In Sql in SQL
? DDL Commands in SQL
DDL stands for Data Definition Language. These commands define or modify the structure of database objects like tables, indexes, and schemas.
? Common DDL Commands
| Command | Purpose | Example |
|---|---|---|
CREATE | Create new database objects (tables, views, indexes, etc.) | sql<br>CREATE TABLE employees (id INT, name VARCHAR(50));<br> |
ALTER | Modify existing database objects | sql<br>ALTER TABLE employees ADD COLUMN email VARCHAR(100);<br> |
DROP | Delete database objects | sql<br>DROP TABLE employees;<br> |
TRUNCATE | Remove all data from a table (fast delete) | sql<br>TRUNCATE TABLE employees;<br> |
RENAME | Rename a database object (varies by DBMS) | sql<br>ALTER TABLE employees RENAME TO staff;<br> (PostgreSQL) |
? Description of Key Commands
1. CREATE
Creates new tables, views, indexes, or other objects.
CREATE TABLE students ( id INT PRIMARY KEY, name VARCHAR(100), age INT);2. ALTER
Modify table structure — add, drop, or modify columns.
ALTER TABLE students ADD COLUMN email VARCHAR(100);3. DROP
Completely removes the table or object and its data.
DROP TABLE students;4. TRUNCATE
Deletes all rows from a table quickly but keeps the structure.
TRUNCATE TABLE students;? Notes
DDL commands typically cause auto-commit in many databases.
Use DDL commands carefully — especially
DROPandTRUNCATEas they can cause data loss.Syntax for some DDL commands can vary slightly between SQL databases.
If you want detailed examples for specific DBMS like MySQL, PostgreSQL, or SQL Server, just ask!