SQL Introduction: What is SQL, History, Relational Databases, RDBMS Comparison & Beginner Examples

Table of Contents

1. Introduction to SQL

SQL History Timeline from 1970s IBM System R to Modern Standards

Q: What is SQL?

SQL (Structured Query Language) is a standardized language used to manage and manipulate data in relational databases. It enables users to create, read, update, and delete data (CRUD operations), define database structures, and manage permissions. SQL is declarative, meaning users specify what data they want, not how to retrieve it.

Q: What is the history of SQL?

Q: Why is SQL important?

2. Understanding Relational Databases and RDBMS Concepts

Relational Database Example: Customers, Orders, and Books Tables with Primary and Foreign Keys

Q: What is a relational database?

A relational database organizes data into tables, where each table (relation) contains rows (records) and columns (attributes). Tables are linked through keys (e.g., primary keys, foreign keys) to model relationships between data entities.

Example: A database with Customers and Orders tables, linked by CustomerID.

Q: What are key RDBMS concepts?

Q: How do relational databases differ from non-relational databases?

4. SQL Syntax Basics

SQL Syntax Cheat Sheet: DDL, DML, SELECT, INSERT, UPDATE, DELETE Examples

Q: What are the core components of SQL syntax?

SQL syntax is divided into categories:

Q: What are common SQL commands and their syntax?

Q: Can you give an example of SQL syntax for a simple database?

Below is an example creating and manipulating a database for a bookstore.

-- Create database
CREATE DATABASE Bookstore;
USE Bookstore; -- Create tables
CREATE TABLE Books ( BookID INT PRIMARY KEY, Title VARCHAR(100) NOT NULL, Author VARCHAR(50), Price DECIMAL(6, 2), PublicationYear INT
); CREATE TABLE Customers ( CustomerID INT PRIMARY KEY, FirstName VARCHAR(50), LastName VARCHAR(50), Email VARCHAR(100) UNIQUE
); CREATE TABLE Orders ( OrderID INT PRIMARY KEY, CustomerID INT, BookID INT, OrderDate DATE, Quantity INT, FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID), FOREIGN KEY (BookID) REFERENCES Books(BookID)
); -- Insert data
INSERT INTO Books (BookID, Title, Author, Price, PublicationYear)
VALUES (1, 'SQL Basics', 'Jane sahil', 29.99, 2020), (2, 'Database Design', 'John Doe', 39.99, 2018); INSERT INTO Customers (CustomerID, FirstName, LastName, Email)
VALUES (1, 'kristal', 'Johnson', 'kristal@example.com'), (2, 'Ram', 'Williams', 'Ram@example.com'); INSERT INTO Orders (OrderID, CustomerID, BookID, OrderDate, Quantity)
VALUES (1, 1, 1, '2025-09-07', 2), (2, 2, 2, '2025-09-08', 1); -- Query data
SELECT b.Title, c.FirstName, c.LastName, o.OrderDate, o.Quantity
FROM Books b
JOIN Orders o ON b.BookID = o.BookID
JOIN Customers c ON o.CustomerID = c.CustomerID
WHERE o.OrderDate >= '2025-09-01'; -- Update data
UPDATE Books
SET Price = Price * 1.05
WHERE PublicationYear < 2020; -- Delete data
DELETE FROM Orders
WHERE Quantity = 1; -- Drop table (cleanup)
DROP TABLE Orders;
DROP TABLE Books;
DROP TABLE Customers;

Description:

Output (for SELECT query):

Title | FirstName | LastName | OrderDate | Quantity
SQL Basics | kristal | Johnson | 2025-09-07 | 2
Database Design | Ram | Williams | 2025-09-08 | 1

Q: What are common mistakes in SQL syntax?

Q: What are best practices for SQL?

Syntax and Structure:

Data Integrity:

Query Optimization:

Security:

General: