Balaprime commited on
Commit
685f1b5
·
verified ·
1 Parent(s): 8b67102

Create database.py

Browse files
Files changed (1) hide show
  1. src/database.py +100 -0
src/database.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sqlite3
2
+
3
+ def initialize_database():
4
+ conn = sqlite3.connect("college.db")
5
+ cursor = conn.cursor()
6
+
7
+ cursor.execute("""
8
+ CREATE TABLE IF NOT EXISTS student (
9
+ student_id INTEGER PRIMARY KEY,
10
+ first_name TEXT,
11
+ last_name TEXT,
12
+ date_of_birth DATE,
13
+ email TEXT,
14
+ phone_number TEXT,
15
+ major TEXT,
16
+ year_of_enrollment INTEGER
17
+ );
18
+ """)
19
+
20
+ cursor.execute("""
21
+ CREATE TABLE IF NOT EXISTS employee (
22
+ employee_id INTEGER PRIMARY KEY,
23
+ first_name TEXT,
24
+ last_name TEXT,
25
+ email TEXT,
26
+ department TEXT,
27
+ position TEXT,
28
+ salary REAL,
29
+ date_of_joining DATE
30
+ );
31
+ """)
32
+
33
+ cursor.execute("""
34
+ CREATE TABLE IF NOT EXISTS course (
35
+ course_id INTEGER PRIMARY KEY,
36
+ course_name TEXT,
37
+ course_code TEXT,
38
+ instructor_id INTEGER,
39
+ department TEXT,
40
+ credits INTEGER,
41
+ semester TEXT,
42
+ FOREIGN KEY (instructor_id) REFERENCES employee(employee_id)
43
+ );
44
+ """)
45
+
46
+ # Clear old data to avoid duplicates
47
+ cursor.execute("DELETE FROM course;")
48
+ cursor.execute("DELETE FROM student;")
49
+ cursor.execute("DELETE FROM employee;")
50
+
51
+ # Insert sample students
52
+ students = [
53
+ (1, "Alice", "Johnson", "2001-06-15", "alice@example.com", "1234567890", "Computer Science", 2019),
54
+ (2, "Bob", "Smith", "2000-04-22", "bob@example.com", "0987654321", "Mechanical Engineering", 2018),
55
+ (3, "Charlie", "Brown", "2002-01-10", "charlie@example.com", "1112223333", "ECE", 2020),
56
+ (4, "Daisy", "Miller", "2001-12-12", "daisy@example.com", "2223334444", "Civil", 2019),
57
+ (5, "Ethan", "Lee", "2000-05-05", "ethan@example.com", "3334445555", "IT", 2018),
58
+ (6, "Fiona", "Clark", "2001-07-07", "fiona@example.com", "4445556666", "CSE", 2020),
59
+ (7, "George", "Adams", "2002-02-02", "george@example.com", "5556667777", "CSE", 2021),
60
+ (8, "Hannah", "Moore", "2001-11-11", "hannah@example.com", "6667778888", "AI", 2019),
61
+ (9, "Ivan", "Davis", "1999-09-09", "ivan@example.com", "7778889999", "ECE", 2017),
62
+ (10, "Julia", "King", "2002-03-03", "julia@example.com", "8889990000", "IT", 2020)
63
+ ]
64
+ cursor.executemany("INSERT INTO student VALUES (?, ?, ?, ?, ?, ?, ?, ?);", students)
65
+
66
+ # Insert sample employees
67
+ employees = [
68
+ (1, "Drake", "Miller", "drake@example.com", "CSE", "Professor", 75000.00, "2015-08-01"),
69
+ (2, "Laura", "White", "laura@example.com", "ECE", "Assistant Professor", 65000.00, "2018-07-10"),
70
+ (3, "James", "Hall", "james@example.com", "IT", "Lecturer", 55000.00, "2019-01-15"),
71
+ (4, "Nancy", "Allen", "nancy@example.com", "Civil", "Professor", 80000.00, "2014-06-12"),
72
+ (5, "Oscar", "Wright", "oscar@example.com", "Mechanical", "Assistant Professor", 60000.00, "2016-10-01"),
73
+ (6, "Rachel", "Baker", "rachel@example.com", "AI", "Lecturer", 52000.00, "2020-03-05"),
74
+ (7, "Steve", "Lopez", "steve@example.com", "CSE", "Professor", 78000.00, "2012-08-20"),
75
+ (8, "Tina", "Hill", "tina@example.com", "ECE", "Lecturer", 53000.00, "2017-09-18"),
76
+ (9, "Uma", "Scott", "uma@example.com", "IT", "Professor", 72000.00, "2013-04-07"),
77
+ (10, "Victor", "Green", "victor@example.com", "CSE", "Assistant Professor", 60000.00, "2018-11-23")
78
+ ]
79
+ cursor.executemany("INSERT INTO employee VALUES (?, ?, ?, ?, ?, ?, ?, ?);", employees)
80
+
81
+ # Insert sample courses
82
+ courses = [
83
+ (1, "Database Systems", "CS301", 1, "CSE", 4, "Fall"),
84
+ (2, "Digital Electronics", "EC202", 2, "ECE", 3, "Spring"),
85
+ (3, "Operating Systems", "CS302", 1, "CSE", 4, "Fall"),
86
+ (4, "Data Structures", "CS201", 10, "CSE", 4, "Spring"),
87
+ (5, "Microprocessors", "EC303", 8, "ECE", 3, "Fall"),
88
+ (6, "Civil Engineering Basics", "CV101", 4, "Civil", 3, "Spring"),
89
+ (7, "Thermodynamics", "ME201", 5, "Mechanical", 4, "Fall"),
90
+ (8, "AI Fundamentals", "AI101", 6, "AI", 3, "Fall"),
91
+ (9, "Web Technologies", "IT301", 3, "IT", 4, "Spring"),
92
+ (10, "Software Engineering", "CS303", 7, "CSE", 4, "Fall")
93
+ ]
94
+ cursor.executemany("INSERT INTO course VALUES (?, ?, ?, ?, ?, ?, ?);", courses)
95
+
96
+ conn.commit()
97
+ conn.close()
98
+
99
+ if __name__ == "__main__":
100
+ initialize_database()