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)
import pandas as pd
def main():
print("=== School Search System ===")
file_path = "school_data.xlsx"
try:
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:
pip install pandas
That's it! Pandas will help us read Excel files easily.
Step 2: Create Search Function (15 minutes)
def simple_search(excel_file, search_term):
results = []
for sheet_name in excel_file.sheet_names:
df = pd.read_excel(excel_file, sheet_name=sheet_name)
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,
'column': col_name,
'value': str(cell_value)
})
return results
Update Your Main Function:
def main():
print("=== School Search System ===")
data = pd.ExcelFile("school_data.xlsx")
print("\nSearching for 'Math'...")
math_results = simple_search(data, "Math")
for result in math_results[:5]:
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)
def find_teacher(excel_file, student_name):
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 student_name in str(cell_value):
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"
def find_students_in_class(excel_file, class_name):
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):
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))
Step 4: Complete Program (10 minutes)
import pandas as pd
def main():
print("=== Student Database Search ===")
try:
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
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]:
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
import sqlite3
def create_database():
conn = sqlite3.connect('school.db')
cursor = conn.cursor()
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