Skip to main content

SQL Commands: The 4 Pillars 🏛️

Mentor's Note: SQL isn't just one thing. It's a collection of sub-languages. Knowing the difference between "Building the House" (DDL) and "Moving Furniture In" (DML) is the first step to database mastery. 💡


🌟 The Scenario: Building a House 🏠

Think of a database like constructing and living in a house.

  1. DDL (Data Definition): The Architect. You build walls, add rooms, or demolish the garage. (Structure) 🏗️
  2. DML (Data Manipulation): The Mover. You bring in furniture, move the sofa, or throw out old trash. (Data) 📦
  3. DCL (Data Control): The Security Guard. You give keys to your family but lock the door for strangers. (Permissions) 🔑
  4. TCL (Transaction Control): The Insurance. You verify everything arrived safely before signing the receipt. (Save/Undo) 📝

🎨 Visual Logic: The Command Hierarchy


💻 1. DDL: Data Definition Language 🏗️

Commands that define the database schema.

CommandActionAnalogy
CREATECreates a new table/dbBuilding a new room
ALTERModifies table structurePainting the walls
DROPDeletes table structureDemolishing the room
TRUNCATEWipes all data, keeps structureEmptying the room completely
-- DDL Example
CREATE TABLE users (id INT, name VARCHAR(50));

💻 2. DML: Data Manipulation Language 📦

Commands that manipulate the data within schema objects.

CommandActionAnalogy
SELECTRetrieves dataLooking for your keys
INSERTAdds new dataBuying a new chair
UPDATEModifies existing dataReupholstering the sofa
DELETERemoves specific dataThrowing away trash
-- DML Example
INSERT INTO users VALUES (1, 'Vishnu');

💻 3. DCL: Data Control Language 🔑

Commands that deal with rights, permissions, and other controls.

CommandActionAnalogy
GRANTGives access privilegesGiving a spare key
REVOKEWithdraws access privilegesChanging the locks
-- DCL Example
GRANT SELECT ON users TO intern_user;

💻 4. TCL: Transaction Control Language 📝

Commands that deal with the transaction of the database.

CommandActionAnalogy
COMMITSaves work permanentlySigning the contract
ROLLBACKRestores to last commitCtrl+Z (Undo)
SAVEPOINTSets a checkpointBookmark in a book
-- TCL Example
UPDATE users SET name = 'VD';
COMMIT; -- Changes are now permanent

💡 Interview Tip 👔

"The most common interview question: What is the difference between DELETE and TRUNCATE?

  • DELETE is DML. It can be rolled back. It scans row by row (Slower).
  • TRUNCATE is DDL. It cannot be rolled back (in Oracle). It resets the table instantly (Faster)."

📈 Learning Path

📍 Visit Us

🏫 VD Computer Tuition Surat

VD Computer Tuition
📍 Address
2/66 Faram Street, Rustompura
Surat395002, Gujarat, India
📞 Phone / WhatsApp
+91 84604 41384
🌐 Website

Computer Classes & Tuition — Areas We Serve in Surat

AdajanAlthanAmroliAthwaAthwalinesBhagalBhatarBhestanCanal RoadChowkCitylightDumasGaurav PathGhod Dod RoadHaziraJahangirpuraKamrejKapodraKatargamLimbayatMagdallaMajura GateMota VarachhaNanpuraNew CitylightOlpadPalPandesaraParle PointPiplodPunaRanderRing RoadRustampuraSachinSalabatpuraSarthanaSosyo CircleUdhnaVarachhaVed RoadVesuVIP Road
📞 Call Sir💬 WhatsApp Sir