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)