script4.sql 2.05 KB
Newer Older
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
-- AFTER RUNNING PYTHON!

ALTER TABLE studentInfo
    drop column imd_band_o;

UPDATE studentInfo SET 
    imd_band = NULL where imd_band = -1;


alter table assessments
    rename column date to date_o,
    rename column weight to weight_o,
    add column date int,
    add column weight int;


update assessments 
    set date_o = "-9999.9" 
    where date_o = "";



--  cant have a negative score likely wont happen 
update assessments 
    set weight_o =  "-9999.9" 
    where weight_o = "";


update assessments 
    set date = CAST(date_o AS DECIMAL),
    weight = CAST(weight_o AS DECIMAL)
    where 1;

update assessments
    set date = NULL 
    where date = -9999.9;

update assessments
    set weight = NULL 
    where weight = -9999.9;


alter table assessments
    drop column date_o, 
    drop column weight_o;



Stefan Vercillo's avatar
Stefan Vercillo committed
49
drop table if exists courseInfo;
50
51
52
53
54

create table courseInfo (
    course_id int AUTO_INCREMENT,
    course_code CHAR(3),
    description varchar(500),
Stefan Vercillo's avatar
Stefan Vercillo committed
55
56
57
    PRIMARY key (course_id)
    -- constraint fk_courseid_courseinfo 
    --     FOREIGN key (course_id) REFERENCES courseOfferings(course_offering_id)
58
59
60
61
62
63
);


insert into courseInfo (course_code)
select distinct code_module from courseOfferings;

Stefan Vercillo's avatar
Stefan Vercillo committed
64
65
66
67
68
69
70
71
72
73

alter table courseOfferings 
    add column course_id INT,
    add constraint foreign key(course_id) references courseInfo(course_id);


UPDATE courseOfferings LEFT JOIN courseInfo ON courseOfferings.code_module = courseInfo.course_code
SET courseOfferings.course_id = courseInfo.course_id;


74
75
76
77
alter table courseOfferings
    drop column code_module, 
    drop column code_presentation,
    rename column module_presentation_length to course_offering_length_in_days;
Stefan Vercillo's avatar
Stefan Vercillo committed
78
79
80
81
82
83
84
85
86
87
88
89

alter table assessments 
    rename column assessment_type to assessment_type_o,
    add column assessment_type ENUM("TMA", "Exam", "CMA");

update assessments
    set assessment_type = assessment_type_o
    where 1;

alter table assessments
    drop column assessment_type_o;

Stefan Vercillo's avatar
Stefan Vercillo committed
90

Stefan Vercillo's avatar
Stefan Vercillo committed
91
92
alter table studentInfo
    drop column highest_education;
Stefan Vercillo's avatar
Stefan Vercillo committed
93
94
95

alter table studentRegistration
    drop column date_unregistration;