1. CREATE
The CREATE command is used to create a new database or a new table. It defines the structure of the table such as columns and data types.
Example: Create Table
CREATE TABLE Students (
ID INT,
Name VARCHAR(50),
Age INT
);
This creates a table named Students with three columns: ID, Name, and Age.
2. ALTER
The ALTER command is used to modify an existing table. You can add, delete, or change columns.
Example: Add Column
ALTER TABLE Students ADD Email VARCHAR(100);
Example: Modify Column
ALTER TABLE Students ALTER COLUMN Name VARCHAR(100);
Example: Drop Column
ALTER TABLE Students DROP COLUMN Email;
These commands modify the structure of the table.
3. DROP
The DROP command is used to delete a table or database completely. It removes both the structure and the data permanently.
Example: Drop Table
DROP TABLE Students;
After executing this command, the table and all its data are permanently deleted.
4. TRUNCATE
The TRUNCATE command is used to remove all records from a table quickly. It does not delete the table structure, only the data.
Example: Truncate Table
TRUNCATE TABLE Students;
After truncating, the table will be empty but still exists.
5. Important Differences
- CREATE → Creates new table or database
- ALTER → Changes structure of existing table
- DROP → Deletes table completely (structure + data)
- TRUNCATE → Deletes only data, keeps table structure
Conclusion
DDL commands are used to manage the structure of a database. They are essential for designing and maintaining database systems.
Your learning journey continues 🚀
