# Student Database Search System

From Excel to Database - A Beginner's Journey

Goal: Build a working search system in 1 hour

Prerequisites: No database experience needed!

# What Is a Relational Database?

Beginner's Guide to Understanding Database Fundamentals

### You'll Learn:

1
What tables, fields, records, and keys are
2
How relationships connect data across tables
3
Why primary keys and foreign keys are critical
4
The role of SQL (Structured Query Language)
5
Real-world examples in banks, hospitals, and apps
Think of it like this:

A relational database is like a digital filing cabinet with labeled folders (tables) that are connected to each other.

Each folder contains specific information that can be linked to other folders.

## Let's Watch and Learn

Take 10 minutes to understand relational databases

### What Is a Relational Database? | Beginner's Guide

By Knewget (30.3K subscribers)

▶ Watch Video on YouTube

This video explains everything you need to know about databases in plain English. Perfect for beginners!

### Key Takeaways:

✓
Tables = Excel sheets with rows and columns
✓
Rows = Individual records (like a student)
✓
Columns = Fields of information (name, grade, etc.)
✓
Primary Key = Unique ID for each row
✓
Foreign Key = Link to another table

## Our 1-Hour MVP Project

Simple Python program to search student schedules

Current Problem:

School data is in messy Excel sheets that are hard to search.

We need to find information quickly!

### Search Examples We'll Build:

1
Find homeroom teacher:
"Who is the homeroom teacher for student Alex?"
2
Find students in a subject:
"Show me all students in Math class 4A"
3
Simple database search:
"Search for any information across all sheets"

## Step 1: Setup (5 minutes)

# 1. Create a new file called "school_search.py" # 2. Open it in any text editor # 3. Start with this basic setup: import pandas as pd def main(): # Main function - everything starts here print("=== School Search System ===") # Load our Excel file file_path = "school_data.xlsx" try: # Read the Excel file excel_file = pd.ExcelFile(file_path) print(f"Success! Found {len(excel_file.sheet_names)} sheets") return excel_file except Exception as e: print(f"Error: {e}") return None if __name__ == "__main__": main()

### To Install Required Libraries:

# Open Command Prompt or Terminal and type: pip install pandas

That's it! Pandas will help us read Excel files easily.

## Step 2: Create Search Function (15 minutes)

# Add this function to your file (under the imports) def simple_search(excel_file, search_term): """Search for any term across all sheets""" results = [] for sheet_name in excel_file.sheet_names: # Read each sheet df = pd.read_excel(excel_file, sheet_name=sheet_name) # Search in all cells for row_idx, row in df.iterrows(): for col_name, cell_value in row.items(): if pd.notna(cell_value): if search_term.lower() in str(cell_value).lower(): results.append({ 'sheet': sheet_name, 'row': row_idx + 2, # Excel row number 'column': col_name, 'value': str(cell_value) }) return results

### Update Your Main Function:

def main(): print("=== School Search System ===") # Load data data = pd.ExcelFile("school_data.xlsx") # Test search print("\nSearching for 'Math'...") math_results = simple_search(data, "Math") for result in math_results[:5]: # Show first 5 results print(f"Found in {result['sheet']}, row {result['row']}: {result['value']}") print(f"\nTotal found: {len(math_results)} results")

## Step 3: Add Specific Searches (15 minutes)

# Function to find homeroom teacher def find_teacher(excel_file, student_name): """Find homeroom teacher for a student""" for sheet_name in excel_file.sheet_names: df = pd.read_excel(excel_file, sheet_name=sheet_name) # Look for student name for idx, row in df.iterrows(): for cell_value in row.values: if pd.notna(cell_value) and student_name in str(cell_value): # Check if teacher info is in same row for col in df.columns: if "teacher" in str(col).lower() or "преподаватель" in str(col).lower(): if pd.notna(row[col]): return row[col] return "Teacher not found"
# Function to find students by class def find_students_in_class(excel_file, class_name): """Find all students in a specific class (like 4A)""" students = [] for sheet_name in excel_file.sheet_names: df = pd.read_excel(excel_file, sheet_name=sheet_name) for idx, row in df.iterrows(): for cell_value in row.values: if pd.notna(cell_value) and class_name in str(cell_value): # Look for student names in this row for col in df.columns: if "name" in str(col).lower() or "фио" in str(col).lower(): if pd.notna(row[col]): students.append(row[col]) return list(set(students)) # Remove duplicates

## Step 4: Complete Program (10 minutes)

# school_search.py - COMPLETE PROGRAM import pandas as pd # [PASTE ALL FUNCTIONS FROM PREVIOUS SLIDES HERE] # 1. simple_search() function # 2. find_teacher() function # 3. find_students_in_class() function def main(): # 1. Load the data print("=== Student Database Search ===") try: # Change this to your actual file name data = pd.ExcelFile("Распределение по группам Технолицей 2025_2026 - 4.xlsx") print(f"✓ Loaded: {len(data.sheet_names)} sheets") except: print("✗ Error: Make sure the Excel file is in the same folder!") return # 2. Example searches print("\n--- Example 1: Find Teacher ---") teacher = find_teacher(data, "Арефьев") print(f"Homeroom teacher: {teacher}") print("\n--- Example 2: Find Students ---") students = find_students_in_class(data, "4A") print(f"Students in 4A: {len(students)} found") for student in students[:3]: # Show first 3 print(f" • {student}") print("\n--- Example 3: General Search ---") results = simple_search(data, "Math") print(f"Found 'Math' {len(results)} times") print("\n=== Search Complete ===") if __name__ == "__main__": main()

### How to Run:

1
Save all code in "school_search.py"
2
Put your Excel file in same folder
3
Open terminal in that folder
4
Type: `python school_search.py`

## Next Step: Real Database

Moving from Excel to SQLite database

# Simple SQLite database setup (future enhancement) import sqlite3 def create_database(): # Connect to database (creates if doesn't exist) conn = sqlite3.connect('school.db') cursor = conn.cursor() # Create tables (like in the video!) cursor.execute('''CREATE TABLE IF NOT EXISTS students ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, grade TEXT, class TEXT, homeroom_teacher_id INTEGER )''') cursor.execute('''CREATE TABLE IF NOT EXISTS teachers ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, subject TEXT )''') conn.commit() conn.close() print("Database created successfully!")
Database vs Excel:

Excel: Good for viewing, bad for searching

Database: Fast searching, relationships, scalable

### Your 1-Hour MVP is Complete!

You've built a working search system that can:

• Search across all Excel sheets

• Find teachers for students

• List students in classes

• Be extended to a real database