Skip to main content

SQL Command Categories

SQL (Structured Query Language) contains many commands, which are categorized based on their functionality:

DDL (Data Definition Language)

Purpose: Defines or changes the structure of database objects. Commands
  • CREATE
  • ALTER
  • DROP
Examples
  • Create a new table
  • Add a new column to an existing table
  • Delete a table from the database
Think
  • Which command would you use to create a new table?
  • Which command would you use to add a new column?
  • Does DDL modify the table structure or the data?

DML (Data Manipulation Language)

Purpose: Adds, updates, or removes data stored in tables. Commands
  • INSERT
  • UPDATE
  • DELETE
Examples
  • Add a new student record
  • Update a student’s email address
  • Delete an inactive student
Think
  • Which command adds new records?
  • Which command modifies existing records?
  • Which command removes records?

DQL (Data Query Language)

Purpose: Retrieves data from one or more tables. Command
  • SELECT
Examples
  • Display all students
  • Display students from the CSE department
  • Display students whose marks are greater than 80
Think
  • Which SQL command is used to retrieve data?
  • Does SELECT change the data stored in the table?

TCL (Transaction Control Language)

Purpose: Controls transactions and ensures data consistency. Commands
  • BEGIN
  • COMMIT
  • ROLLBACK
Examples
  • Start a transaction
  • Save all changes permanently
  • Undo changes before they are committed
Think
  • Which command permanently saves changes?
  • Which command cancels uncommitted changes?
  • Why are transactions important?

Creating Tables

Naming Conventions

[!TIP] Plural Table Names: It is a very common industry standard and database convention to name tables in their plural form (e.g., employees, departments, students) because a table represents a collection of multiple records. Columns, however, are named in the singular form (e.g., employee_id, salary) as they represent single attributes of a record.

Syntax

Explanation

  • PRIMARY KEY — Uniquely identifies each row.
  • NOT NULL — Prevents NULL values.
  • FOREIGN KEY — Creates a relationship with another table.

Practice

Create a students table with student_id, student_name, and email.

ALTER TABLE

Used to modify an existing table.

Add a Column

Rename a Column

Practice

Add a phone column to the employees table.

DROP TABLE

Deletes an entire table permanently.
Note: All data in the table is permanently deleted.

Practice

Delete the students table.

INSERT Statement

Used to insert new rows into a table.

Insert a Single Row

Insert Multiple Rows

Insert by Specifying Columns

Practice

Insert an employee named Anitha with a salary of 55000.

UPDATE Statement

Used to modify existing records.

Syntax

Important: Always use a WHERE clause unless you intend to update every row.

Practice

Increase Rahul’s salary to ₹75,000.

DELETE Statement

Deletes one or more rows.
Important: Omitting the WHERE clause deletes all rows.

Practice

Delete the employee named Sneha.

Summary

In this chapter, you learned:
  • SQLite basics
  • SQL command categories
  • SQLite data types
  • CREATE TABLE
  • ALTER TABLE
  • DROP TABLE
  • INSERT
  • UPDATE
  • DELETE
The next chapter focuses on Setting Up SQLite Database, where you will install the VS Code extension, create your database file, and populate it with practice data.