>_
EngineeringNotes
Back to SQL Hub

SQL Introduction

The standard language for relational database management systems.

1Core Concepts

Database is a container which is used to store data in a systematic format so that data can be easily retrieved, edited, and managed (perform query).

There are multiple mechanisms to store data, like Excel, files, etc., but to store data which is massive in size, a flat file is very unrealistic.

Example: Fetching Total SpendingFrom a file: Requires writing complex code to parse the file line by line.
From a database: Just a single SQL query (1-2 lines).

The Ecosystem

  • Database: Stores data.
  • SQL: Language to speak to the database.
  • DBMS: Manages the database.
  • S
    Server: Where the database lives.
User👤
↔ SQL ↔
Database

SQL acts as the secure bridge between the user/application and the database.

2SQL Terminologies

DatumSingular of Data. A single piece of information.
DataPlural of Datum. Raw facts and figures.
DatabaseCollection of data.
TableData organized in rows and columns.
RecordA single row in a table.
RDBMSRelational Database Management System.
SchemaThe structure or blueprint of the database.
💡

Note on SQL Syntax

SQL is a Case-Insensitive language.SELECT andselect are treated as the same command.

3Types of Databases

1. Relational Database

Think of it like Excel spreadsheets. Data is stored in tables, and there are logical relations (connections) between those tables.

MySQLPostgreSQLSQLiteMariaDB (OpenSource MySQL)
2. Key-Value (NoSQL)

Stores data as a collection of key-value pairs.

RedisDynamoDB
3. Graph Database

Uses graph structures with nodes, edges, and properties.

Neo4j
4. Document Database

Data structure doesn't matter. Stores data in JSON-like documents.

MongoDB
5. Column-Based

Stores data in columns rather than rows.

4SQL Command Types

CategoryFull FormCommands
DDLData Definition LanguageCREATE, ALTER, DROP, TRUNCATE
DMLData Manipulation LanguageINSERT, UPDATE, DELETE
DCLData Control LanguageGRANT, REVOKE
TCLTransaction Control LanguageCOMMIT, ROLLBACK
DQLData Query LanguageSELECT