Objective
Create a comprehensive system for managing educational course videos, including course organization, video chapters, transcriptions, and student progress tracking.
Step 1: Create Courses Table
Define course catalog.
CREATE TABLE courses (
id INTEGER PRIMARY KEY,
course_code VARCHAR(50) NOT NULL UNIQUE,
course_name VARCHAR(200) NOT NULL,
description TEXT,
category VARCHAR(100),
skill_level VARCHAR(50),
instructor_id INTEGER,
instructor_name VARCHAR(200),
thumbnail IMAGE(JPEG),
preview_video VIDEO(MP4),
duration_hours DECIMAL(5, 2),
total_videos INTEGER DEFAULT 0,
language VARCHAR(50) DEFAULT 'English',
has_certificate BOOLEAN DEFAULT TRUE,
price DECIMAL(10, 2),
status VARCHAR(50) DEFAULT 'draft',
published_at TIMESTAMP,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Step 2: Create Course Modules Table
Organize courses into modules.
CREATE TABLE course_modules (
id INTEGER PRIMARY KEY,
course_id INTEGER NOT NULL,
module_number INTEGER NOT NULL,
module_title VARCHAR(200),
description TEXT,
duration_minutes INTEGER,
is_free_preview BOOLEAN DEFAULT FALSE,
prerequisites TEXT,
learning_objectives TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (course_id) REFERENCES courses(id)
);
Step 3: Create Course Videos Table
Store video content.
CREATE TABLE course_videos (
id INTEGER PRIMARY KEY,
module_id INTEGER NOT NULL,
video_number INTEGER NOT NULL,
video_title VARCHAR(200),
description TEXT,
video_file VIDEO(MP4),
duration_seconds INTEGER,
resolution VARCHAR(20),
file_size_mb DECIMAL(10, 2),
thumbnail IMAGE(JPEG),
transcript TEXT,
captions_file TEXT,
has_quiz BOOLEAN DEFAULT FALSE,
is_downloadable BOOLEAN DEFAULT FALSE,
view_count INTEGER DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (module_id) REFERENCES course_modules(id)
);
Step 4: Create Video Chapters Table
Define video sections.
CREATE TABLE video_chapters (
id INTEGER PRIMARY KEY,
video_id INTEGER NOT NULL,
chapter_number INTEGER NOT NULL,
chapter_title VARCHAR(200),
start_time_seconds INTEGER NOT NULL,
end_time_seconds INTEGER,
description TEXT,
thumbnail IMAGE(JPEG),
FOREIGN KEY (video_id) REFERENCES course_videos(id)
);
Step 5: Create Student Enrollments Table
Track course enrollments.
CREATE TABLE student_enrollments (
id INTEGER PRIMARY KEY,
student_id VARCHAR(50) NOT NULL,
course_id INTEGER NOT NULL,
enrolled_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
started_at TIMESTAMP,
completed_at TIMESTAMP,
progress_percent DECIMAL(5, 2) DEFAULT 0,
last_accessed TIMESTAMP,
certificate_issued BOOLEAN DEFAULT FALSE,
certificate_url VARCHAR(500),
FOREIGN KEY (course_id) REFERENCES courses(id)
);
Step 6: Create Video Progress Table
Track viewing progress.
CREATE TABLE video_progress (
id INTEGER PRIMARY KEY,
enrollment_id INTEGER NOT NULL,
video_id INTEGER NOT NULL,
watched_seconds INTEGER DEFAULT 0,
total_seconds INTEGER,
progress_percent DECIMAL(5, 2) DEFAULT 0,
is_completed BOOLEAN DEFAULT FALSE,
completed_at TIMESTAMP,
last_position_seconds INTEGER DEFAULT 0,
watch_count INTEGER DEFAULT 1,
last_watched TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (enrollment_id) REFERENCES student_enrollments(id),
FOREIGN KEY (video_id) REFERENCES course_videos(id)
);
Step 7: Insert Sample Courses
Add course catalog.
INSERT INTO courses (id, course_code, course_name, description, category, skill_level, instructor_id, instructor_name, duration_hours, total_videos, language, price, status, published_at) VALUES
(1, 'WEB-101', 'Web Development Fundamentals', 'Learn HTML, CSS, and JavaScript basics', 'Web Development', 'Beginner', 1, 'John Smith', 24.5, 45, 'English', 49.99, 'published', '2023-06-01 00:00:00'),
(2, 'PY-201', 'Python for Data Science', 'Master Python for data analysis and visualization', 'Data Science', 'Intermediate', 2, 'Sarah Johnson', 32.0, 60, 'English', 79.99, 'published', '2023-07-15 00:00:00'),
(3, 'ML-301', 'Machine Learning Essentials', 'Build ML models from scratch', 'Machine Learning', 'Advanced', 3, 'Michael Chen', 40.0, 75, 'English', 99.99, 'published', '2023-09-01 00:00:00'),
(4, 'DESIGN-101', 'UI/UX Design Principles', 'Create beautiful user interfaces', 'Design', 'Beginner', 4, 'Emily Brown', 18.0, 35, 'English', 39.99, 'published', '2023-10-01 00:00:00'),
(5, 'DB-201', 'Database Design Mastery', 'Design scalable database architectures', 'Database', 'Intermediate', 5, 'David Wilson', 28.0, 52, 'English', 69.99, 'published', '2023-11-01 00:00:00');
Step 8: Insert Course Modules
Add module structure.
INSERT INTO course_modules (id, course_id, module_number, module_title, description, duration_minutes, is_free_preview) VALUES
(1, 1, 1, 'Introduction to HTML', 'HTML basics and document structure', 180, TRUE),
(2, 1, 2, 'CSS Styling', 'Styling web pages with CSS', 240, FALSE),
(3, 1, 3, 'JavaScript Basics', 'Programming fundamentals with JS', 300, FALSE),
(4, 1, 4, 'Building Projects', 'Hands-on web projects', 360, FALSE),
(5, 2, 1, 'Python Fundamentals', 'Python syntax and data types', 200, TRUE),
(6, 2, 2, 'NumPy and Pandas', 'Data manipulation libraries', 280, FALSE),
(7, 2, 3, 'Data Visualization', 'Creating charts and graphs', 240, FALSE),
(8, 3, 1, 'ML Foundations', 'Understanding machine learning concepts', 220, TRUE),
(9, 3, 2, 'Supervised Learning', 'Classification and regression', 320, FALSE),
(10, 3, 3, 'Neural Networks', 'Deep learning fundamentals', 380, FALSE);