Basics
SQL lets you create, read, update, and delete data stored in tables (rows = records, columns = fields).
Core building blocks
Tables: Defined by a schema (column names + data types).
Keys & relationships:
Primary key (PK): unique ID in a table (e.g.,
ClientID).Foreign key (FK): column that points to a PK in another table (e.g.,
Projects.ClientIDreferencesClients.ClientID).
Main SQL categories
DDL (Data Definition Language): structure
This allows you to create what's known as a table.
CREATE TABLE Clients ( ClientID INT PRIMARY KEY, Name VARCHAR(100) NOT NULL, ZipCode CHAR(5) );
DML (Data Manipulation Language): data
This allows you to directly change data in the SQL database.
INSERT INTO Clients (ClientID, Name, ZipCode) VALUES (1, 'Acme Co', '60601'); UPDATE Clients SET ZipCode = '60602' WHERE ClientID = 1; DELETE FROM Clients WHERE ClientID = 1;
DQL (Data Query Language): reading data (mostly
SELECT)This is allowing you to look for a certain criterion in the data and search for it without changing the data.
SELECT Name, ZipCode FROM Clients WHERE ZipCode = '60601' ORDER BY Name ASC;
The SELECT “recipe”
Examples
1) Basic filter
2) JOIN (parent/child via PK↔FK)
3) WHERE logic
4) Calculations & grouping
5) Concatenation & filtering by zip (therapists not in 72511)
Last updated