diff --git a/createdb.sql b/createdb.sql index a214ea038ea9be4ca86e84498ea28b3be3fcde4c..e3a6f9e8ece27c41a469bf69df97e4ffbb14b253 100644 --- a/createdb.sql +++ b/createdb.sql @@ -15,13 +15,15 @@ subscribed bool, phonenum int); DROP TABLE IF EXISTS `Students`; CREATE TABLE `Students`( -studentID int primary key, +studentID int(20), +primary key(studentID), fname varchar(35), lname varchar(35), -- The UK Government Data Standards Catalogue reccomends 35 characters for each the first name and last name bday date, dayjoined date , parentsID int(20), +groupID int(20), FOREIGN KEY (parentsID) REFERENCES Parents(parentID) -- parent ID is stored in student rather than the parents table so that one parent can have many children -- and not one child can have many parents. A child may have multiple parents irl but they would share an @@ -39,8 +41,8 @@ CREATE TABLE `Volunteers`( SGlastchecked date, emergencycontact varchar(20) ); -DROP TABLE IF EXISTS `Session`; -CREATE TABLE `Session`( +DROP TABLE IF EXISTS `Sessions`; +CREATE TABLE `Sessions`( sessionID int(20), primary key (sessionID), leaderID int(20), @@ -48,19 +50,43 @@ CREATE TABLE `Session`( duration int(10), FOREIGN KEY (leaderID) REFERENCES Volunteers(VolunteerID), maxAttendees int(10), + groupid int(20), Nohelpers int(10)); DROP TABLE IF EXISTS `Badge`; CREATE TABLE `Badge`( BadgeID int(20), + primary key(BadgeID), badgeName varchar(35), - requirementID int(20) + badgeDesc varchar(255), + RequirementID int(20) ); DROP TABLE IF EXISTS `BadgeAwarded`; CREATE TABLE `BadgeAwarded`( - studentID int(20), + awardedID int(20), + primary key(awardedID), + awardedto int(20), awardedby int(20), - BadgeID int(20), - dateAwarded date + Badgeawarded int(20), + dateAwarded date, + FOREIGN KEY (awardedto) REFERENCES Students(studentID), + FOREIGN KEY (awardedby) REFERENCES Volunteers(VolunteerID), + FOREIGN KEY (Badgeawarded) REFERENCES Badge(BadgeID) ); - - select * from Session; \ No newline at end of file +-- DROP TABLE IF EXISTS `Badgereqs`; +CREATE TABLE `Badgereqs`( + RequirementID int(20), + primary key(RequirementID), + mustbecompleted int(20), + tocomplete int(20), + FOREIGN KEY (mustbecompleted) REFERENCES Badge(BadgeID), + FOREIGN KEY (tocomplete) REFERENCES Badge(BadgeID) +); +DROP TABLE IF EXISTS `StudentAttendance`; +CREATE TABLE `StudentAttendance`( + studentID int(20), + sessionID int(20), + FOREIGN KEY (studentID) REFERENCES Students(studentID), + FOREIGN KEY (sessionID) REFERENCES Sessions(SessionID) +); +Alter table `Badge`ADD FOREIGN KEY (RequirementID) REFERENCES Badgereqs(RequirementID); + select * from StudentAttendance; \ No newline at end of file