Tuesday, May 26, 2026
Cohort 3 | Project CloudIgnite Topics: SQL Fundamentals, Data Types, DDL & DML, CSV Import/Export Duration: ~3 hours
Key Takeaways
- SQL tools: SQLite (beginner), MySQL/PostgreSQL (production), DB Browser for SQLite (GUI)
- DDL:
CREATE DATABASE/TABLE,ALTER TABLE,DROP TABLE,SHOW,DESCRIBE - DML:
INSERT INTO(with/without column names),UPDATE SET,DELETE FROM - FLOAT cannot store exact values (5 may become 5.0001); use DECIMAL/REAL for precision
- CHAR(n) = fixed length; VARCHAR(n) = variable length — use CHAR when length is always fixed
- CSV import:
LOAD DATA INFILE; export:SELECT INTO OUTFILE - Data cleaning: common errors (data entry, wrong type, duplicates); TRIM, CONCAT, UPPER/LOWER functions
- EC2 + SSM Session Manager: connect to instances without SSH keys
Table of Contents
- Tools for Practicing SQL
- SQL Data Types
- Database & Table Design
- DDL — Data Definition Language
- DML — Data Manipulation Language
- CSV Files & Data Import/Export
- Data Cleaning
- Connecting to EC2 via SSM Session Manager
- Lab Walkthrough Summary
- Knowledge Check Answers
- AWS CLF-C02 Relevance
1. Tools for Practicing SQL
- SQLite — recommended for beginners; no setup required, supports all common SQL commands.
- DB Browser for SQLite — a free, open-source GUI for SQLite. Available for Windows, Mac, Linux.
- Website: sqlitebrowser.org
- Just install and use — no server setup needed.
- MySQL / PostgreSQL — more feature-rich, used in production environments; requires server setup.
- Python — has built-in support for SQLite; you can run SQLite queries directly inside Python scripts.
- ORM (Object-Relational Mapper) — preferred in backend development for security (prevents SQL injection), but learn raw SQL first before using ORMs.
- JavaScript: Sequelize
- Golang: GORM
- Python: SQLAlchemy (common)
2. SQL Data Types
Numeric Types
| Type | Description |
|---|---|
INTEGER | Whole numbers (e.g. 1, 42, -7) |
SMALLINT / BIGINT | Smaller/larger range integers |
DECIMAL | Mix of integer + fractional; stores exact values |
FLOAT | Fractional numbers; approximate (small rounding error possible) |
REAL | Similar to FLOAT but higher precision (smaller error margin) |
DOUBLE | 64-bit; can store up to ~100 significant digits, but also approximate |
⚠️ Important: Floating-point numbers cannot store exact values. A stored value of
5may be represented as5.0001or4.99999. UseDECIMALorREALwhen precision matters (e.g. financial or scientific data).
Why does FLOAT work with less memory but more range?
- Integer (32-bit) → max ~10^10
- FLOAT (32-bit) → max ~10^38 digits
- Trade-off: larger range, but sacrifices exactness.
String / Character Types
| Type | Description |
|---|---|
CHAR(n) | Fixed-length string. Always uses n bytes of memory regardless of actual content length. Best when length is always the same (e.g. country code = 3 chars, phone number = 11 digits). |
VARCHAR(n) | Variable-length string. Uses only as many bytes as the content + 1 extra byte to store the length. More memory-efficient for varied-length data. |
Rule of thumb: Use
CHARwhen length is always fixed. UseVARCHARwhen length varies — otherwise you waste memory.
Date & Time Types
| Type | Description |
|---|---|
DATE | Year, Month, Day |
TIME | Hour, Minutes, Seconds |
TIMESTAMP | Date + Time combined |
Special Types
ENUM— A predefined list of allowed values. The column only accepts values within the list.- Example:
ENUM('Asia', 'Europe', 'Africa', 'North America', 'South America', 'Oceania', 'Antarctica') - If you try to insert a value not in the list, it violates the constraint and the insert will fail.
- Example:
3. Database & Table Design
Relational Database
- A relational database is a collection of data items with predefined relationships.
- Tables are linked using primary keys and foreign keys.
Primary Key
- Uniquely identifies each record in a table.
- No two rows can have the same primary key value.
Foreign Key & Referential Integrity
- A foreign key in one table references a primary key in another table.
- Referential integrity rule: Foreign key values must match an existing primary key value in the referenced table.
Example Table Relationships (Any Company Books)
Customer ──< Orders >── Products
(one-to-many) (one-to-many)
- Customer → places many Orders
- Orders → contains many Products
Suggested Columns per Table
| Table | Columns |
|---|---|
| Customer | customer_id, name, contact_number, address |
| Product | product_id, name, price, unit, location |
| Order | order_id, customer_id, [list of product_ids] |
Naming Conventions
- Use snake_case (underscores) — most common in SQL.
- Be consistent — pick one style and stick to it. Never mix styles.
4. DDL — Data Definition Language
DDL statements define and modify the structure of the database (schema). They do not insert or retrieve data.
Key DDL Commands
-- Create a new database
CREATE DATABASE world;
-- Select/use a database
USE world;
-- View all databases
SHOW DATABASES;
-- Create a table
CREATE TABLE city (
name VARCHAR(30) NOT NULL,
reason VARCHAR(30) NOT NULL
);
-- View all tables in current database
SHOW TABLES;
-- View column structure of a table
SHOW COLUMNS FROM country;
-- or
DESCRIBE country;
-- Rename a column
ALTER TABLE country RENAME COLUMN contintent TO continent;
-- Add a new column
ALTER TABLE city ADD COLUMN test VARCHAR(20) NOT NULL;
-- Modify an existing column (e.g. change length)
ALTER TABLE city MODIFY COLUMN test VARCHAR(100);
-- Delete (drop) a table — IRREVERSIBLE without backup!
DROP TABLE city;
-- Delete (drop) a database
DROP DATABASE world;
⚠️
DROP TABLEandDROP DATABASEare permanent. Always have a backup before running these.
DESCRIBE Statement
- Shows the schema (structure) of a table: column names, data types, constraints.
- Always use
DESCRIBE <table>before inserting data so you know the expected types.
DESCRIBE country;
5. DML — Data Manipulation Language
DML statements manipulate data within existing tables (insert, update, delete, query).
INSERT
-- Insert a single row (with column names — best practice)
INSERT INTO country (code, name, continent, region, surface_area)
VALUES ('BRA', 'Brazil', 'South America', 'South America', 8547403.0);
-- Insert without column names (only when inserting ALL columns in exact order)
INSERT INTO country VALUES ('IRL', 'Ireland', 'Europe', 'British Isles', 70273.0, ...);
-- Insert multiple rows at once
INSERT INTO country (code, name) VALUES ('AUS', 'Australia'), ('NZL', 'New Zealand');
When to include column names:
- Always include if any field is optional (nullable).
- Always include if your data is not in the same order as the table columns.
- Safe practice: always include column names.
SELECT (basic usage in lab context)
-- Select all columns
SELECT * FROM country;
-- Select specific columns
SELECT code, name, continent FROM country;
-- Filter with WHERE
SELECT * FROM country WHERE code = 'IRL';
-- Filter with IN (multiple values)
SELECT * FROM country WHERE code IN ('IRL', 'AUS');
-- Check current database
SELECT DATABASE();
UPDATE
-- Update all rows (no condition)
UPDATE country SET population = 0;
-- Update multiple columns
UPDATE country SET population = 1000, surface_area = 100;
-- Update a specific row
UPDATE country SET population = 5000000, surface_area = 70273 WHERE code = 'IRL';
DELETE
-- Delete all rows from a table (table structure remains)
DELETE FROM country;
Note:
DELETE FROM tableremoves all data but keeps the table.DROP TABLEremoves the table entirely.
Semicolons
- Every SQL query must end with a semicolon (
;). - Without it, the database engine waits for more input on the next line.
6. CSV Files & Data Import/Export
What is a CSV?
- CSV = Comma-Separated Values
- A plain text file where each row is a record, and each value is separated by a comma.
- The first row is typically column headers (not actual data).
- File extension
.csv— but it is just a text file; you can open it in any text editor or Excel.
Text Files vs Binary Files
- Text files — human-readable; can be opened in a text editor (e.g.
.csv,.py,.json,.xml,.html,.sh). - Binary files — not directly readable (e.g.
.db,.exe,.mp3,.mp4). - File extensions identify the type/purpose but do not change the underlying file format.
- On Linux/Unix, extensions are optional for text files (e.g.
/etc/grouphas no extension).
Importing CSV to a Table
LOAD DATA INFILE '/path/to/file.csv'
INTO TABLE city
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS; -- Skip the header row
Steps:
- Verify CSV structure matches the table schema (column count, data types, order).
- Create the target table if it doesn't exist.
- Run
LOAD DATA INFILE.
Exporting a Table to CSV
SELECT id, name, country_code
FROM city
INTO OUTFILE '/path/to/output.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
Importing from a .sql File
mysql -u root -p < world.sql
Or from within the MySQL/MariaDB shell, the instructor ran the source file to pre-populate the world database with 237 country records.
7. Data Cleaning
Before importing data, clean it to avoid errors and constraint violations.
Common Data Errors
| Error Type | Example | Solution |
|---|---|---|
| Data entry error | Typo in a name | Input validation |
| Wrong data type | Age stored as "twenty" instead of 20 | Data type enforcement |
| Wrong code | Incorrect country code | Lookup/reference table or ENUM |
| Illogical data | Birthdate set to year 2035 | Range constraints (e.g. CHECK) |
| Missing data | Null where value is required | NOT NULL constraint |
| Duplicate data | Same record inserted twice | UNIQUE constraint |
Useful String Cleaning Functions in SQL
| Function | Purpose |
|---|---|
LEFT(str, n) | Get first n characters |
RIGHT(str, n) | Get last n characters |
TRIM(str) | Remove leading/trailing spaces |
CONCAT(a, b) | Combine strings |
LOWER(str) | Convert to lowercase |
UPPER(str) | Convert to uppercase |
Note: SQL does not natively support full regular expressions like programming languages do. Use
LIKEwith wildcards for pattern matching.
8. Connecting to EC2 via SSM Session Manager
The lab uses AWS Systems Manager (SSM) Session Manager instead of SSH to connect to EC2.
Steps
- Go to AWS Management Console → EC2
- Select your running EC2 instance
- Click Connect
- Choose the Session Manager tab (not EC2 Instance Connect)
- Click Connect
No SSH key required for Session Manager.
Paste in Session Manager Terminal
- Use Ctrl + Shift + V to paste in the browser-based terminal.
Basic Navigation Once Connected
# Switch to root user
sudo su
# Navigate to ec2-user home directory
cd /home/ec2-user
# List files
ls
9. Lab Walkthrough Summary
Lab: Creating Tables and Data Types (DDL)
- Connect to EC2 via SSM Session Manager
- Log in to MariaDB:
mysql -u root -p<password> - Create database:
CREATE DATABASE world; - Select database:
USE world; - Create
countrytable with columns including anENUMfor continent - Fix a typo in column name using
ALTER TABLE ... RENAME COLUMN - Create a
citytable withnameandreasoncolumns (VARCHAR,NOT NULL) - Drop
citytable:DROP TABLE city; - Drop
countrytable:DROP TABLE country; - Drop
worlddatabase:DROP DATABASE world; - Submit lab before ending.
Lab: Insert, Update, Delete (DML)
- Connect to MariaDB, navigate to
worlddatabase - Insert rows manually into
countrytable - Use
SELECT * FROM countryto verify - Use
UPDATE country SET population = 0to update all rows - Use
UPDATE ... WHERE code = 'AUS'for conditional update - Use
DELETE FROM countryto remove all rows - Import data from
world.sqlfile to repopulate the database - Use
SELECT code, name FROM country— confirmed 237 rows of country data loaded - Submit lab before ending.
10. Knowledge Check Answers
| Question | Answer |
|---|---|
| Purpose of DDL | Create and modify the structure of data |
| Function of SELECT statement | Retrieve/query data from a table |
| What describes a foreign key? | A column that references a primary key in another table |
| Referential integrity means... | Foreign key values must match an existing primary key value |
| Purpose of DML | Perform queries and manipulate data within schema |
| What is a relational database? | A collection of data items with predefined relationships |
| SQL command to create a table | CREATE TABLE |
| Purpose of a primary key | To uniquely identify each record |
11. AWS CLF-C02 Relevance
The majority of this lecture covers relational database concepts and SQL, which are foundational knowledge. The following items are directly or indirectly relevant to the AWS Certified Cloud Practitioner (CLF-C02) exam.
✅ Relevant Topics
| Lecture Topic | CLF-C02 Connection |
|---|---|
| Relational databases (tables, primary/foreign keys, schemas) | Underpins understanding of Amazon RDS (Relational Database Service) |
| Database types (SQL-based) | CLF-C02 distinguishes between relational (RDS, Aurora) vs non-relational (DynamoDB) databases |
| MySQL / MariaDB on EC2 | Relates to the concept of running databases on EC2 (self-managed) vs using managed services like RDS |
| EC2 instances (used in the lab) | EC2 is a core CLF-C02 service under compute |
| AWS Systems Manager Session Manager | SSM is part of AWS Systems Manager, a CLF-C02 relevant management tool — it provides secure, keyless access to EC2 instances |
| AWS Management Console navigation | Basic console familiarity is assumed in the CLF-C02 exam context |
📌 CLF-C02 Exam Tips Related to This Lecture
- Amazon RDS supports MySQL, MariaDB, PostgreSQL, Oracle, SQL Server, and Amazon Aurora. It is a managed relational database service — AWS handles backups, patching, and availability.
- Amazon Aurora is AWS's cloud-native relational DB, compatible with MySQL and PostgreSQL, with higher performance.
- Amazon DynamoDB is the AWS non-relational (NoSQL) database — contrasts with what was covered today.
- EC2 + self-installed DB (like today's lab) = unmanaged — you handle everything yourself. RDS = managed.
- AWS Systems Manager (SSM) is tested under the Management & Governance domain. Session Manager specifically removes the need for open SSH ports (port 22), improving security posture — a relevant security concept for CLF-C02.
❌ Not Directly Tested in CLF-C02
- Raw SQL syntax (
INSERT,ALTER TABLE, etc.) is not tested in CLF-C02. - SQLite is not an AWS service and is not tested.
- Detailed floating-point precision differences are not tested.
Notes compiled from lecture — May 26, 2026 Next class: Thursday (tomorrow is a public holiday — Eid Mubarak 🌙) Next topics: NULL statement, SELECT in depth, KC review