Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 184 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# ================================================================
# .gitignore for SQL Lab Project
# ================================================================

# ================================================================
# IDE and Editor Files
# ================================================================

# IntelliJ IDEA
.idea/
*.iml
*.iws
*.ipr
out/

# Visual Studio Code
.vscode/
*.code-workspace

# Sublime Text
*.sublime-project
*.sublime-workspace

# Eclipse
.project
.metadata
.classpath
.settings/

# NetBeans
nbproject/
build/
nbbuild/
dist/
nbdist/

# ================================================================
# Operating System Files
# ================================================================

# macOS
.DS_Store
.AppleDouble
.LSOverride
._*
.Spotlight-V100
.Trashes

# Windows
Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/

# Linux
*~
.directory

# ================================================================
# Database Files
# ================================================================

# MySQL
*.sql~
*.sql.bak
*.sql.backup
mysql-data/
mysql-bin/

# SQLite
*.db
*.sqlite
*.sqlite3

# PostgreSQL
*.pgsql
*.dump

# Database backup files
*.backup
*.bak
*.old

# ================================================================
# Temporary and Log Files
# ================================================================

# Logs
*.log
logs/
*.log.*

# Temporary files
*.tmp
*.temp
*~
*.swp
*.swo
.*.swp

# Cache
*.cache
cache/

# ================================================================
# Project Specific
# ================================================================

# Don't ignore the actual SQL solution files
!exercise1_blog_database.sql
!exercise2_airline_database.sql
!exercise3_queries.sql
!SOLUTION_DOCUMENTATION.sql

# Local database configuration files (if any)
db-config.local.sql
credentials.sql
local-settings.sql

# Environment files
.env
.env.local
.env.*.local

# ================================================================
# Archives and Compressed Files
# ================================================================

# Compressed files (exclude if not needed)
*.zip
*.tar
*.tar.gz
*.rar
*.7z

# ================================================================
# Node.js (if used for any tooling)
# ================================================================

node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
package-lock.json
yarn.lock

# ================================================================
# Java (if used for any tooling)
# ================================================================

*.class
*.jar
*.war
*.ear
target/

# ================================================================
# Documentation Build Output
# ================================================================

# PDF outputs (if generating documentation)
*.pdf

# HTML generated docs (keep markdown sources)
docs/_build/
site/

# ================================================================
# Test and Coverage Reports
# ================================================================

coverage/
*.cover
.coverage
htmlcov/

# ================================================================
# Git Attributes
# ================================================================

# Don't ignore .gitignore itself
!.gitignore
!.gitattributes

76 changes: 76 additions & 0 deletions exercise1_blog_database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
-- ================================================================
-- Exercise 1: Normalize a Blog Database
-- ================================================================

-- Step 1: Normalization to 3NF
-- Original table had redundancy with author names repeated
-- Normalized into:
-- - authors table (stores unique authors)
-- - posts table (stores posts with FK to authors)

-- ================================================================
-- Step 2: DDL - CREATE TABLE statements
-- ================================================================

CREATE TABLE authors (
author_id INT PRIMARY KEY AUTO_INCREMENT,
author_name VARCHAR(100) NOT NULL UNIQUE
);

CREATE TABLE posts (
post_id INT PRIMARY KEY AUTO_INCREMENT,
author_id INT NOT NULL,
title VARCHAR(255) NOT NULL,
word_count INT NOT NULL CHECK (word_count > 0),
views INT DEFAULT 0 CHECK (views >= 0),
FOREIGN KEY (author_id) REFERENCES authors(author_id)
);

-- Add index for performance on frequent queries
CREATE INDEX idx_posts_author ON posts(author_id);
CREATE INDEX idx_posts_views ON posts(views);

-- ================================================================
-- Step 3: INSERT sample data
-- ================================================================

-- Insert authors first (referenced table)
INSERT INTO authors (author_name) VALUES
('Maria Charlotte'),
('Juan Perez'),
('Gemma Alcocer');

-- Insert posts
INSERT INTO posts (author_id, title, word_count, views) VALUES
(1, 'Best Paint Colors', 814, 14),
(2, 'Small Space Decorating Tips', 1146, 221),
(1, 'Hot Accessories', 986, 105),
(1, 'Mixing Textures', 765, 22),
(2, 'Kitchen Refresh', 1242, 307),
(1, 'Homemade Art Hacks', 1002, 193),
(3, 'Refinishing Wood Floors', 1571, 7542);

-- ================================================================
-- Verification Queries
-- ================================================================

-- View all data
SELECT
a.author_name,
p.title,
p.word_count,
p.views
FROM posts p
JOIN authors a ON p.author_id = a.author_id
ORDER BY p.post_id;

-- Total posts per author
SELECT
a.author_name,
COUNT(*) as total_posts,
SUM(p.views) as total_views
FROM posts p
JOIN authors a ON p.author_id = a.author_id
GROUP BY a.author_name
ORDER BY total_views DESC;

Loading