πŸŽ‰ 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?

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;

How SQL Works: The Architecture

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

The Relational Model

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

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

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

SQL Dialects

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

Need Expert SQL Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement