ποΈ Day 1: Introduction to SQL and Databases
ποΈ Day 1: Introduction to SQL and Databases
Welcome to Day 1 of your SQL learning journey!
Today, weβll explore the basics β what data is, what a database does, and how SQL helps us manage data efficiently.
π What is Data?
Data is simply a collection of information.
Example: Names, phone numbers, employee records, sales reports β all are data.
π¬ What is SQL (Structured Query Language)?
SQL stands for Structured Query Language.
It is a language used to communicate with databases β to store, retrieve, and manage data.
ποΈ What is a Database (DB)?
A Database is a structured place where data is stored and retrieved efficiently.
Think of it as a digital filing cabinet.
π Why Do We Need a Database?
-
β Data Security β Protects data from unauthorized access.
-
π¦ Handles Large Data β Can store millions of records efficiently.
-
π₯ Multi-User Access β Multiple users can access it simultaneously.
-
π Access Control β Permissions can be granted or revoked.
-
πΎ Prevents Data Loss β Backup and recovery mechanisms help preserve data.
π§± Database Structures (Models)
The structure or model defines how data is organized in a database.
1. Hierarchical Model
-
Data is stored in a tree-like structure (ParentβChild relationship).
-
Example: Each employee (child) belongs to one department (parent).
-
Disadvantage: You canβt easily access data from other branches.
2. Network Model
-
Data is stored using many-to-many relationships.
-
Advantage: You can access related records easily.
-
Disadvantage: More complex to design and query.
3. Entity-Relationship Model (ER Model)
-
Represents data as entities (tables) and their relationships.
-
Fast data fetching but may consume more space.
4. Relational Model (RDBMS)
-
Stores similar kinds of data in tables.
-
Allows relationships between tables using keys (Primary, Foreign).
-
Examples of RDBMS: Oracle, MySQL, SQL Server, Snowflake, Azure SQL Database
βοΈ SQL Commands and Categories
SQL commands are grouped into five main categories:
1. DDL β Data Definition Language
Used to define or modify the structure of the database.
Commands:
-
CREATE β Create new tables or databases
-
ALTER β Modify table structure
-
RENAME β Rename a table
-
DROP β Delete a table completely
-
TRUNCATE β Delete all records but keep the table structure
π DELETE vs TRUNCATE vs DROP
| Command | Action | Keeps Structure? | Can Rollback? |
|---|---|---|---|
| DELETE | Removes selected rows | β Yes | β Yes |
| TRUNCATE | Removes all rows | β Yes | β No |
| DROP | Removes table completely | β No | β No |
2. DML β Data Manipulation Language
Used to manipulate or modify the data inside tables.
Commands:
-
INSERT β Add new records
-
UPDATE β Modify existing records
-
DELETE β Remove records
Example:
3. TCL β Transaction Control Language
Used to manage transactions in a database (commit, rollback, checkpoints).
Commands:
-
COMMIT β Save all changes permanently
-
ROLLBACK β Undo uncommitted changes
-
SAVEPOINT β Create checkpoints to partially undo operations
Example:
4. DCL β Data Control Language
Used to control user access to the database.
Commands:
-
GRANT β Give permissions
-
REVOKE β Remove permissions
5. DQL β Data Query Language
Used to fetch or query data from the database.
Command:
-
SELECT β Retrieve data from tables
Examples:
Common SQL Clauses
-
SELECT β Columns to fetch
-
FROM β Table name
-
WHERE β Conditions
Example:
β Summary
On Day 1, youβve learned:
-
What data and databases are
-
Why databases are needed
-
Database models and structures
-
SQL command types: DDL, DML, TCL, DCL, DQL
Next, youβll learn about constraints, keys, and relationships between tables β essential for building strong SQL foundations.