πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
Search courses…
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

SQL Introduction

SQL FundamentalsGetting Started🟒 Free Lesson

Advertisement

SQL Fundamentals

SQL Introduction

SQL (Structured Query Language) is the standard language for working with relational databases. It enables you to query, insert, update, and delete data efficiently.

  • Query Data β€” Ask questions about your data and retrieve meaningful insights
  • Manipulate Data β€” Insert, update, and delete records with precision
  • Define Structures β€” Create and modify database tables, views, and indexes

SQL is the universal language of data β€” every major company relies on it.

What is SQL?

DfSQL (Structured Query Language)

A standardized programming language designed for managing and manipulating data held in relational database management systems (RDBMS). SQL became a standard of the American National Standards Institute (ANSI) in 1986.

Core Capabilities

OperationSQL CommandDescriptionExample
Query dataSELECTRetrieve data from tablesSELECT * FROM users;
Insert dataINSERT INTOAdd new rowsINSERT INTO users (name) VALUES ('Alice');
Update dataUPDATEModify existing rowsUPDATE users SET name = 'Bob' WHERE id = 1;
Delete dataDELETERemove rowsDELETE FROM users WHERE id = 1;
Create tablesCREATE TABLEDefine new tablesCREATE TABLE users (id INT PRIMARY KEY);
Modify tablesALTER TABLEChange table structureALTER TABLE users ADD email TEXT;
Remove tablesDROP TABLEDelete entire tablesDROP TABLE users;
-- A complete SQL query example
SELECT first_name, last_name, email
FROM customers
WHERE city = 'New York'
ORDER BY last_name;

SQL is declarative β€” you describe what data you want, not how to retrieve it. The database engine figures out the best way to execute your query.

How SQL Works: The Architecture

User ApplicationApp CodeSQL QueryDatabase SystemSQL ParserQuery OptimizerExecution EngineStorage EngineStorageData FilesIndex FilesTransaction LogsDatabase

The Relational Model

DfRelational Model

A data model based on first-order predicate logic, invented by Edgar F. Codd in 1970. Data is organized into relations (tables) where each row represents a fact and each column represents an attribute of that fact.

ConceptDescriptionSQL Equivalent
RelationA two-dimensional tableTABLE
TupleA row in a relationROW / RECORD
AttributeA column in a relationCOLUMN / FIELD
DomainAllowed values for an attributeDATA TYPE
CardinalityNumber of rows in a tableCOUNT(*)
DegreeNumber of columns in a tableNumber of columns

Set Theory Operations

SQL operations are based on mathematical set theory:

-- UNION: Combines two sets (removes duplicates)
SELECT city FROM customers
UNION
SELECT city FROM suppliers;

-- INTERSECT: Returns common elements in both sets
SELECT city FROM customers
INTERSECT
SELECT city FROM suppliers;

-- EXCEPT: Returns elements in first set but not second
SELECT city FROM customers
EXCEPT
SELECT city FROM suppliers;
Set A: CustomersNew YorkLondonParisSet B: SuppliersNew YorkTokyoParisUNIONNew YorkLondonParisTokyoINTERSECTNew YorkParisEXCEPTLondonA βˆͺ B = all unique cities | A ∩ B = common cities | A βˆ’ B = cities only in A

Types of SQL Statements

DfSQL Statement Categories

SQL statements are grouped into four main categories based on their purpose: DDL (Data Definition Language), DML (Data Manipulation Language), DCL (Data Control Language), and TCL (Transaction Control Language).

SQL StatementsDDLDMLDCLTCLCREATEALTERDROPTRUNCATESELECTINSERTUPDATEDELETEGRANTREVOKECOMMITROLLBACKSAVEPOINT
CategoryFull NameCommandsPurpose
DDLData Definition LanguageCREATE, ALTER, DROP, TRUNCATEDefine database structure
DMLData Manipulation LanguageSELECT, INSERT, UPDATE, DELETEManipulate data
DCLData Control LanguageGRANT, REVOKEControl access permissions
TCLTransaction Control LanguageCOMMIT, ROLLBACK, SAVEPOINTManage transactions

DDL Example

-- CREATE: Make a new table
CREATE TABLE employees (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL
);

-- ALTER: Add a column to existing table
ALTER TABLE employees ADD COLUMN email TEXT;

-- DROP: Remove a table completely
DROP TABLE employees;

DML Example

-- SELECT: Retrieve data
SELECT * FROM employees WHERE salary > 50000;

-- INSERT: Add new data
INSERT INTO employees (id, name, email)
VALUES (1, 'Alice', 'alice@company.com');

-- UPDATE: Modify existing data
UPDATE employees SET salary = 75000 WHERE id = 1;

-- DELETE: Remove data
DELETE FROM employees WHERE id = 1;

Query Execution Flow

DfQuery Execution

When you submit a SQL query, the database engine processes it through several stages: parsing (syntax check), validation (semantic check), optimization (execution plan), and finally execution (retrieving results).

User Writes SQL QuerySQL ParserSyntax CheckQuery ValidatorSemantic CheckQuery OptimizerCreates Execution PlanChoose PlanFull Table ScanIndex ScanReturn Results

SQL Dialects

Different databases use slightly different SQL dialects. The fundamentals are the same, but specific functions and syntax may vary between MySQL, PostgreSQL, SQL Server, and SQLite.

DialectKey DifferencesBest For
MySQLAUTO_INCREMENT, LIMIT syntaxWeb applications
PostgreSQLJSON support, CTEs, Window functionsComplex queries
SQL ServerTOP syntax, IDENTITY columnsEnterprise systems
SQLiteFile-based, minimal configMobile & embedded apps

Who Uses SQL?

RoleHow They Use SQLCommon Tasks
Data AnalystsQuery data for insights and reportsAd-hoc queries, dashboards
Data ScientistsExtract data for analysis and modelingFeature engineering, pipelines
Software EngineersBuild data-driven applicationsCRUD operations, APIs
Database AdministratorsManage and optimize databasesPerformance tuning, backups
Business AnalystsGenerate business intelligence reportsKPI tracking, trend analysis

Performance Tips

  1. Always use specific column names instead of SELECT *
  2. Add indexes on columns used in WHERE clauses
  3. Limit result sets with LIMIT/TOP when possible
  4. Avoid SELECT DISTINCT by using proper WHERE conditions
  5. Use EXPLAIN/EXPLAIN ANALYZE to understand query plans

Summary

Key Takeaways

  1. SQL is the standard language for relational database management
  2. SQL can query, insert, update, delete, and define data structures
  3. SQL is declarative β€” you describe what you want, not how to get it
  4. SQL statements are categorized into DDL, DML, DCL, and TCL
  5. Practice is the best way to master SQL fundamentals
⭐

Premium Content

SQL Introduction

Unlock this lesson and 900+ advanced tutorials with a Premium plan.

🎯End-to-end Projects
πŸ’ΌInterview Prep
πŸ“œCertificates
🀝Community Access

Already a member? Log in

Need Expert SQL Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement