Why Databases Exist & SQL Basics
From Excel limits to tables, data types, INSERT, SELECT and ORDER BY, plus the DDL / DML / DQL split, on SQL Server.
1. The Crux in 60 Seconds
Excel breaks at scale
About 1 million records per file, slow filters, painful sharing by email. Databases have no such cap and serve many users.
Define before you store
A database table needs its columns and data types declared first with CREATE TABLE. Excel lets you type anything anywhere.
Insert, then query
INSERT INTO puts rows in; SELECT reads them out. Even Amazon's UI ends up firing an INSERT behind an API call.
Three command families
DDL changes structure, DML changes data, DQL (SELECT) only reads. DROP kills the table; DELETE empties it.
2. Foundational Concepts & Comparisons
Excel (early-Amazon story)
- No need to declare columns or types; add a column any time
- Limit of 1 million records; 10 million records means 10 Excel files
- Filters on a 1M-row file hang; analytics limited to charts and pivots
- Sharing means emailing files around
Database (DBMS)
- No cap: buy more memory, space, hardware as needed
- Columns and data types must be defined beforehand
- Many users can be given access to the same data
- Examples named: Oracle, Microsoft SQL Server (used in class), Teradata, Amazon Redshift, MySQL
Analogy: drive, folder, file
Think of your computer: a database is like a drive (C:, D:), a schema is a folder inside that drive, and a table lives inside the folder. A server can hold many databases, each holding many schemas and tables.
| Level | Class example |
|---|---|
| Server | Local SQL Server instance |
| Database | System DBs master, model + the one created in class |
| Schema | dbo (default), later HR, sales |
| Table | Amazon orders, orders |
Environment setup
- Download SQL Server 2019 Express; run the exe.
- At the end, choose to install SSMS (SQL Server Management Studio): the server stores data, SSMS is the client you query with.
- Open SSMS to see your local server and databases.
- New database: right-click Databases, New Database, name it, OK. The command
CREATE DATABASE namealso works. - New query: click New Query and pick the database to work in.
MySQL Workbench: allowed; roughly 80 to 90% is the same, some functions differ (Google the alternative).