-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateDB.py
More file actions
89 lines (74 loc) · 1.96 KB
/
CreateDB.py
File metadata and controls
89 lines (74 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import sqlite3 as sql
con = sql.connect('studentperformance.db') #Establish connection to database
curs = con.cursor() #Create a cursor to interact with database
#Not using autoincrement on StudentID as will be generating that using pandas
curs.execute('''
CREATE TABLE IF NOT EXISTS Student
(StudentID INTEGER PRIMARY KEY,
SchoolID INTEGER,
Sex TEXT,
Age INTEGER,
AddressType TEXT,
FamilySize INTEGER,
GuardianOneID INTEGER,
GuardianTwoID INTEGER,
ParentLivingStatus TEXT,
Commute TEXT,
ReasonForSchoolChoice TEXT,
TimeSpentStudying TEXT,
FailureCount INTEGER,
EducationalSupport BOOLEAN,
ParentalSupport BOOLEAN,
ReceivesTutoring BOOLEAN,
ExtraCurricular BOOLEAN,
AttendedNursery BOOLEAN,
PlansOnHigherEducation BOOLEAN,
HasInternet BOOLEAN,
InRelationship BOOLEAN,
FamilyRelationshipRating INTEGER,
BusynessScale INTEGER,
SocialScore INTEGER,
WeekdayAlcoholConsumption INTEGER,
WeekendAlcoholConsumption INTEGER,
HealthScore INTEGER,
AbsenceCount INTEGER)
''')
curs.execute('''
CREATE TABLE IF NOT EXISTS School
(SchoolID INTEGER PRIMARY KEY AUTOINCREMENT,
Country TEXT,
Name TEXT)
''')
curs.execute('''
CREATE TABLE IF NOT EXISTS Exam
(ExamID INTEGER PRIMARY KEY AUTOINCREMENT,
Code TEXT,
Description TEXT)''')
curs.execute('''
CREATE TABLE IF NOT EXISTS ExamEntry
(ExamEntryID INTEGER PRIMARY KEY AUTOINCREMENT,
ExamID INTEGER,
StudentID INTEGER,
Grade INTEGER
)''')
curs.execute('''
CREATE TABLE IF NOT EXISTS EducationLevel
(EducationLevelID INTEGER PRIMARY KEY AUTOINCREMENT ,
Description TEXT)''')
#Not autoincrementing GuardianID as will create that using Pandas
curs.execute('''
CREATE TABLE IF NOT EXISTS Guardian
(GuardianID INTEGER PRIMARY KEY,
RelationshipToStudent TEXT,
EducationLevelID INTEGER,
OccupationID INTEGER,
IsPrimary BOOLEAN)
''')
curs.execute('''
CREATE TABLE IF NOT EXISTS Occupation
(ID INTEGER PRIMARY KEY AUTOINCREMENT,
Description TEXT)''')
# curs.execute('''
# UPDATE EducationLevel
# SET EducationLevelID = EducationLevelID - 1''')
con.commit()