SQL Study Material
Databases & RDBMS
What is a Database?
A database is an organized collection of data stored electronically, so that it can be searched, updated and shared safely by many users at the same time.
A Database Management System (DBMS) is the software that stores the data and answers requests for it, for example MySQL or PostgreSQL.
RDBMS
RDBMS stands for Relational Database Management System. In a relational database, data is stored in tables, and tables are linked to each other through shared values (keys).
RDBMS is the basis for SQL and for all modern database systems such as MySQL, SQL Server, Oracle, PostgreSQL and SQLite.
Tables, Rows and Columns
A table is a collection of related data, made of columns and rows. This is the Customers table used throughout this tutorial:
| CustomerID | CustomerName | ContactName | City | Country |
|---|---|---|---|---|
| 1 | Aarav Traders | Aarav Shah | Mumbai | India |
| 2 | Blue Harbor Foods | Emma Clark | London | UK |
| 3 | Cedar & Co | Liam Brown | Toronto | Canada |
| 4 | Delta Mart | Priya Nair | Bengaluru | India |
| 5 | Evergreen Grocers | Noah Wilson | New York | USA |
| 6 | Fjord Supplies | Ingrid Olsen | Oslo | Norway |
| 7 | Golden Spoon | Mei Chen | NULL | Singapore |
| 8 | Harbor Lights | Olivia Martin | London | UK |
- Column (field): one piece of information for every record, e.g.
City. - Row (record): one complete entry, e.g. the customer "Delta Mart".
- Primary key: a column whose value uniquely identifies each row, here
CustomerID.
Why Relational?
Instead of repeating customer details on every order, the Orders table stores only the CustomerID. The two tables are related through that column, so a customer's address is stored once and every order points to it.
- No duplication: each fact is stored in one place.
- Integrity: constraints stop invalid data, such as an order for a customer that does not exist.
- Flexibility: joins let you combine tables in any way at query time.