1️⃣ CREATE TABLE – Used to create a new table in the database.
CREATE TABLE Students (
ID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT,
Grade VARCHAR(10)
);
2️⃣ ALTER TABLE – Used to modify an existing table structure.
➤ Add a new column
ALTER TABLE Students ADD Email VARCHAR(100);
➤ Rename a column (syntax may vary by SQL version)
ALTER TABLE Students RENAME COLUMN Name TO FullName;
➤ Change data type
ALTER TABLE Students MODIFY Age SMALLINT;
➤ Drop a column
ALTER TABLE Students DROP COLUMN Grade;
3️⃣ DROP TABLE – Permanently deletes the entire table and its data.
DROP TABLE Students;
⚠️ Caution: This action cannot be undone.
4️⃣ TRUNCATE TABLE – Removes all rows but keeps the table structure.
TRUNCATE TABLE Students;
5️⃣ RENAME TABLE – Change the table name.
RENAME TABLE Students TO Alumni;
6️⃣ DESCRIBE Table – View the structure of a table.
DESCRIBE Students;
💡 Pro Tips:
- Always back up data before making structural changes.
- Use
IF EXISTSorIF NOT EXISTSto avoid errors.
DROP TABLE IF EXISTS Students;
CREATE TABLE IF NOT EXISTS Teachers (...);
💬 Double Tap ❤️ For More!
Top comments (0)