Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SUPERGEEKS-SQL
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Finlay White
SUPERGEEKS-SQL
Commits
669d65e7
Commit
669d65e7
authored
2 years ago
by
Finlay White
Browse files
Options
Downloads
Patches
Plain Diff
not null unique + md5 ready
parent
5b5b8977
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
createdb.sql
+34
-20
34 additions, 20 deletions
createdb.sql
with
34 additions
and
20 deletions
createdb.sql
+
34
−
20
View file @
669d65e7
...
@@ -3,7 +3,7 @@ CREATE SCHEMA `SuperGeeks`;
...
@@ -3,7 +3,7 @@ CREATE SCHEMA `SuperGeeks`;
USE
`SuperGeeks`
;
USE
`SuperGeeks`
;
DROP
TABLE
IF
EXISTS
`Parents`
;
DROP
TABLE
IF
EXISTS
`Parents`
;
CREATE
TABLE
`Parents`
(
CREATE
TABLE
`Parents`
(
parentID
int
(
2
0
)
not
null
,
parentID
varchar
(
4
0
)
not
null
unique
,
primary
key
(
parentID
),
primary
key
(
parentID
),
fname
varchar
(
35
),
fname
varchar
(
35
),
lname
varchar
(
35
),
lname
varchar
(
35
),
...
@@ -15,15 +15,15 @@ subscribed bool,
...
@@ -15,15 +15,15 @@ subscribed bool,
phonenum
int
);
phonenum
int
);
DROP
TABLE
IF
EXISTS
`Students`
;
DROP
TABLE
IF
EXISTS
`Students`
;
CREATE
TABLE
`Students`
(
CREATE
TABLE
`Students`
(
studentID
int
(
20
)
,
studentID
varchar
(
40
)
not
null
unique
,
primary
key
(
studentID
),
primary
key
(
studentID
),
fname
varchar
(
35
),
fname
varchar
(
35
),
lname
varchar
(
35
),
lname
varchar
(
35
),
-- The UK Government Data Standards Catalogue reccomends 35 characters for each the first name and last name
-- The UK Government Data Standards Catalogue reccomends 35 characters for each the first name and last name
bday
date
,
bday
date
,
dayjoined
date
,
dayjoined
date
,
parentsID
int
(
2
0
),
parentsID
varchar
(
4
0
),
groupID
int
(
2
0
),
groupID
varchar
(
4
0
),
FOREIGN
KEY
(
parentsID
)
REFERENCES
Parents
(
parentID
)
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
-- 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
-- and not one child can have many parents. A child may have multiple parents irl but they would share an
...
@@ -32,7 +32,7 @@ FOREIGN KEY (parentsID) REFERENCES Parents(parentID)
...
@@ -32,7 +32,7 @@ FOREIGN KEY (parentsID) REFERENCES Parents(parentID)
DROP
TABLE
IF
EXISTS
`Volunteers`
;
DROP
TABLE
IF
EXISTS
`Volunteers`
;
CREATE
TABLE
`Volunteers`
(
CREATE
TABLE
`Volunteers`
(
VolunteerID
int
(
20
)
,
VolunteerID
varchar
(
40
)
not
null
unique
,
primary
key
(
VolunteerID
),
primary
key
(
VolunteerID
),
fname
varchar
(
35
),
fname
varchar
(
35
),
lname
varchar
(
35
),
lname
varchar
(
35
),
...
@@ -43,30 +43,30 @@ CREATE TABLE `Volunteers`(
...
@@ -43,30 +43,30 @@ CREATE TABLE `Volunteers`(
);
);
DROP
TABLE
IF
EXISTS
`Sessions`
;
DROP
TABLE
IF
EXISTS
`Sessions`
;
CREATE
TABLE
`Sessions`
(
CREATE
TABLE
`Sessions`
(
sessionID
int
(
20
)
,
sessionID
varchar
(
40
)
not
null
unique
,
primary
key
(
sessionID
),
primary
key
(
sessionID
),
leaderID
int
(
2
0
),
leaderID
varchar
(
4
0
),
location
varchar
(
55
),
location
varchar
(
55
),
duration
int
(
10
),
duration
int
(
10
),
FOREIGN
KEY
(
leaderID
)
REFERENCES
Volunteers
(
VolunteerID
),
FOREIGN
KEY
(
leaderID
)
REFERENCES
Volunteers
(
VolunteerID
),
maxAttendees
int
(
10
),
maxAttendees
int
(
10
),
groupid
int
(
2
0
),
groupid
varchar
(
4
0
),
Nohelpers
int
(
10
));
Nohelpers
int
(
10
));
DROP
TABLE
IF
EXISTS
`Badge`
;
DROP
TABLE
IF
EXISTS
`Badge`
;
CREATE
TABLE
`Badge`
(
CREATE
TABLE
`Badge`
(
BadgeID
int
(
20
)
,
BadgeID
varchar
(
40
)
not
null
unique
,
primary
key
(
BadgeID
),
primary
key
(
BadgeID
),
badgeName
varchar
(
35
),
badgeName
varchar
(
35
),
badgeDesc
varchar
(
255
),
badgeDesc
varchar
(
255
),
RequirementID
int
(
2
0
)
RequirementID
varchar
(
4
0
)
);
);
DROP
TABLE
IF
EXISTS
`BadgeAwarded`
;
DROP
TABLE
IF
EXISTS
`BadgeAwarded`
;
CREATE
TABLE
`BadgeAwarded`
(
CREATE
TABLE
`BadgeAwarded`
(
awardedID
int
(
20
),
awardedID
int
(
20
)
not
null
unique
,
primary
key
(
awardedID
),
primary
key
(
awardedID
),
awardedto
int
(
2
0
),
awardedto
varchar
(
4
0
),
awardedby
int
(
2
0
),
awardedby
varchar
(
4
0
),
Badgeawarded
int
(
2
0
),
Badgeawarded
varchar
(
4
0
),
dateAwarded
date
,
dateAwarded
date
,
FOREIGN
KEY
(
awardedto
)
REFERENCES
Students
(
studentID
),
FOREIGN
KEY
(
awardedto
)
REFERENCES
Students
(
studentID
),
FOREIGN
KEY
(
awardedby
)
REFERENCES
Volunteers
(
VolunteerID
),
FOREIGN
KEY
(
awardedby
)
REFERENCES
Volunteers
(
VolunteerID
),
...
@@ -74,19 +74,33 @@ CREATE TABLE `BadgeAwarded`(
...
@@ -74,19 +74,33 @@ CREATE TABLE `BadgeAwarded`(
);
);
-- DROP TABLE IF EXISTS `Badgereqs`;
-- DROP TABLE IF EXISTS `Badgereqs`;
CREATE
TABLE
`Badgereqs`
(
CREATE
TABLE
`Badgereqs`
(
RequirementID
int
(
20
)
,
RequirementID
varchar
(
40
)
not
null
unique
,
primary
key
(
RequirementID
),
primary
key
(
RequirementID
),
mustbecompleted
int
(
2
0
),
mustbecompleted
varchar
(
4
0
),
tocomplete
int
(
2
0
),
tocomplete
varchar
(
4
0
),
FOREIGN
KEY
(
mustbecompleted
)
REFERENCES
Badge
(
BadgeID
),
FOREIGN
KEY
(
mustbecompleted
)
REFERENCES
Badge
(
BadgeID
),
FOREIGN
KEY
(
tocomplete
)
REFERENCES
Badge
(
BadgeID
)
FOREIGN
KEY
(
tocomplete
)
REFERENCES
Badge
(
BadgeID
)
);
);
DROP
TABLE
IF
EXISTS
`StudentAttendance`
;
DROP
TABLE
IF
EXISTS
`StudentAttendance`
;
CREATE
TABLE
`StudentAttendance`
(
CREATE
TABLE
`StudentAttendance`
(
studentID
int
(
2
0
),
studentID
varchar
(
4
0
),
sessionID
int
(
2
0
),
sessionID
varchar
(
4
0
),
FOREIGN
KEY
(
studentID
)
REFERENCES
Students
(
studentID
),
FOREIGN
KEY
(
studentID
)
REFERENCES
Students
(
studentID
),
FOREIGN
KEY
(
sessionID
)
REFERENCES
Sessions
(
SessionID
)
FOREIGN
KEY
(
sessionID
)
REFERENCES
Sessions
(
SessionID
)
);
);
Alter
table
`Badge`
ADD
FOREIGN
KEY
(
RequirementID
)
REFERENCES
Badgereqs
(
RequirementID
);
Alter
table
`Badge`
ADD
FOREIGN
KEY
(
RequirementID
)
REFERENCES
Badgereqs
(
RequirementID
);
select
*
from
StudentAttendance
;
\ No newline at end of file
-- procedures
DELIMITER
^^
-- error handling
CREATE
PROCEDURE
CreateParent
(
IN
accNum
INT
,
IN
firstname
VARCHAR
(
25
),
IN
accBalance
float
)
BEGIN
DECLARE
CONTINUE
HANDLER
FOR
1062
SELECT
'Duplicate account number'
AS
MESSAGE
;
INSERT
INTO
accounts
(
accNo
,
fname
,
balance
)
VALUES
(
accNum
,
firstname
,
accBalance
);
END
^^
DELIMITER
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment