Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
What the course covers
What a relational database is, and how tables, rows, and columns work.
- Core SQL: SELECT, INSERT, UPDATE, DELETE, and table creation.
- Filtering, sorting, grouping, built-in functions, sub-queries, and joins.
- Connect Python to a database, run SQL from a notebook, and work with real data sets.
- Bonus: views, stored procedures, transactions, and JOIN types.
| Module | Main focus |
|---|---|
| 1. Getting Started with SQL | Databases, SELECT, WHERE, COUNT, DISTINCT, LIMIT, INSERT, UPDATE, DELETE |
| 2. Introduction to Relational Databases and Tables | Keys, constraints, DDL vs DML, CREATE, ALTER, DROP, TRUNCATE, SQL scripts |
| 3. Intermediate SQL | LIKE, BETWEEN, sorting, grouping, functions, sub-queries, multiple tables |
| 4. Accessing Databases using Python | DB-API, ibm_db, SQL magic, pandas, analyzing data with Python |
| 5. Course Assignment | Real data sets, built-in functions, final assignment, final exam |
| 6. Bonus Module: Advanced SQL for Data Engineers | Views, stored procedures, ACID transactions, JOIN statements |
Module 1: Getting Started with SQL
A database stores data in tables. A table has rows and columns.
- SQL is the language for relational databases.
- SELECT reads data. WHERE filters rows.
- COUNT counts rows. DISTINCT removes duplicates. LIMIT caps the result size.
- INSERT adds rows. UPDATE changes rows. DELETE removes rows. Always use WHERE with UPDATE and DELETE.
Module 2: Introduction to Relational Databases and Tables
Primary key: a unique id for each row. It cannot be null.
- Foreign key: a column that points to a primary key in another table.
- DDL builds tables: CREATE, ALTER, DROP, TRUNCATE.
- Constraints protect data: NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY.
- TRUNCATE removes all rows but keeps the table. DROP removes the whole table.
Module 3: Intermediate SQL
LIKE with % and _ finds string patterns. BETWEEN finds a range.
- ORDER BY sorts rows. Use ASC or DESC.
- GROUP BY groups rows. HAVING filters groups after grouping. WHERE filters rows before grouping.
- Built-in functions: COUNT, SUM, AVG, MIN, MAX, UPPER, LENGTH, ROUND, and date functions.
- A sub-query is a query inside a query. A JOIN combines tables.
Module 4: Accessing Databases using Python
DB-API steps: connect, cursor, execute, fetch, then close.
- ibm_db is the IBM driver used with Db2 in this course.
- SQL magic (%sql, %%sql) runs SQL in a Jupyter notebook.
- pandas.read_sql puts a query result into a DataFrame. Close the connection when done.
Module 5: Course Assignment
The assignment uses real data sets and built-in SQL functions.
- Write one query per question. Check table and column names first.
- Test small parts first, then combine them. Save your queries.
Module 6: Bonus Module: Advanced SQL for Data Engineers
A view is a saved query. It acts like a virtual table.
- A stored procedure is SQL saved on the database. You call it with parameters.
- A transaction is all or nothing. COMMIT saves it. ROLLBACK undoes it.
- ACID means Atomicity, Consistency, Isolation, and Durability.
- INNER JOIN keeps matches only. LEFT, RIGHT, and FULL OUTER joins keep unmatched rows.
Check yourself
Answer each question first, then open it to check the answer.
1Which statement reads data from a table? a) INSERT · b) SELECT · c) DROP · d) UPDATE
b) SELECT. SELECT reads rows from a table.
2You need the different values in a column, with no repeats. Which keyword do you use? a) LIMIT · b) COUNT · c) DISTINCT · d) ORDER
c) DISTINCT. DISTINCT removes repeated values.
3What is a primary key? a) A column with a unique value for each row · b) A saved query · c) A type of join · d) A copy of a table
a) A column with a unique value for each row. A primary key is unique and not null.
4A column that points to a primary key in another table is a: a) first column · b) password · c) foreign key · d) function
c) foreign key. A foreign key links to a primary key in another table.
5Which statement is DDL? a) INSERT · b) UPDATE · c) DELETE · d) CREATE TABLE
d) CREATE TABLE. CREATE TABLE is DDL. INSERT, UPDATE, and DELETE are DML.
6What is the difference between DROP and TRUNCATE? a) They do the same thing · b) DROP removes the table itself; TRUNCATE removes all rows and keeps the table · c) TRUNCATE removes the database · d) DROP removes one row only
b) DROP removes the table itself; TRUNCATE removes all rows and keeps the table. TRUNCATE clears rows. DROP deletes the table too.
7What does HAVING do? a) It filters groups after GROUP BY · b) It sorts the rows · c) It joins two tables · d) It creates a table
a) It filters groups after GROUP BY. HAVING works on groups; WHERE works on rows.
8LIKE '%data%' matches: a) only strings that start with "data" · b) only strings that end with "data" · c) any string that contains "data" · d) numbers only
c) any string that contains "data". The % means any characters before and after.
9Which order is correct for DB-API? a) execute, connect, fetch · b) fetch, execute, connect · c) connect, fetch, execute · d) connect, cursor, execute, fetch
d) connect, cursor, execute, fetch. Connect, then cursor, then execute, then fetch.
10Which join keeps all rows from the left table, even with no match? a) INNER JOIN · b) CROSS JOIN · c) LEFT JOIN · d) SELF JOIN
c) LEFT JOIN. LEFT JOIN keeps every row of the left table.
11In ACID, what does the A mean? a) Atomicity: all or nothing · b) Accuracy · c) Access · d) Aggregation
a) Atomicity: all or nothing. Atomicity means the whole transaction happens or none of it does.
Study and exam tips
Learn the DDL and DML split. CREATE and ALTER are DDL. INSERT, UPDATE, and DELETE are DML.
- WHERE filters rows. HAVING filters groups. Exams love this pair.
- A primary key must be unique and not null. A foreign key can repeat.
- Remember the DB-API order: connect, cursor, execute, fetch, close.
- INNER JOIN gives matches only. OUTER joins keep the rows with no match.