SQL DML - Data Manipulation Language
CRUD operations
Relational Model
MID | Name | HomePhone | DoB |
1224 | Tom Morello | 7577777777 | 30/05/1964 |
6719 | Zack de la Rocha | 8044444444 | 12/01/1970 |
2743 | Brad Wilk | 9199999999 | 05/09/1968 |
MUSICIAN
Relation (table)
Tuples (rows/records)
Attributes (columns/fields)
Relational Model
MID | Name | HomePhone | DoB | BID |
1224 | Tom Morello | 7577777777 | 30/05/1964 | 7373 |
6719 | Zack de la Rocha | 8044444444 | 12/01/1970 | 7373 |
2743 | Brad Wilk | 9199999999 | 05/09/1968 | 7373 |
MUSICIAN
BID | Name | Formed | City |
7373 | Rage Against The Machine | 1991 | Los Angeles |
0201 | The Beatles | 1960 | Liverpool |
BAND
Relational Model
PatID | Name | HomePhone | DoB |
1224 | Tom Morello | 7577777777 | 30/05/1964 |
6719 | Zack de la Rocha | 8044444444 | 12/01/1970 |
2743 | Brad Wilk | 9199999999 | 05/09/1968 |
PATIENT
Relation (table)
Tuples (rows/records)
Attributes (columns/fields)
Create a table
DROP TABLE `PERSON`;
CREATE TABLE `PERSON` (
`PersonID` INT NOT NULL,
`TEAM_TeamName` VARCHAR(45) NOT NULL,
`PersonType` INT NOT NULL);
CRUD
insert
INSERT [INTO] tablename (col1, col2, …, coln)
VALUES (value1, value2, …, valuen)
insert into TEAM
(TeamName, City, Division, PERSON_ManagerID)
values
('Crawford Cows', 'Crawford', 'West', NULL);
update
UPDATE tablename SET assignments
[WHERE condition]
update TEAM
set Division = 'Western'
where Division = 'West';
delete
DELETE FROM tablename
[WHERE condition]
delete from TEAM
where Division like 'West%';
SELECT statement
SELECT column(s)
FROM table(s)
WHERE condition
ORDER BY column(s)
LIMIT number
SQL aggregation functions
Examples (2019 dataset)
Examples - more specific results
SELECT min(runtime)
FROM title
WHERE year = 2020;�
SELECT count(*)
FROM title, aka
WHERE title.tid = aka.tid
AND title.title = 'Moana';
GROUP BY clause
SELECT category, count(*)
FROM castcrew
GROUP BY category
ORDER BY count(*) DESC;