Вы находитесь на странице: 1из 7

Understanding the Data Items:

 Student last name


Question Answer Provide the reason why you set the data item up this
way – why not another way / another set up?
What is the Column LastName -- Reason not required --
Name in the entity?
Which Entity does the Students -- Reason not required --
Data item belong to?
Is it a PK? (or part of a No Last name may not be unique, or can be blank
PK?)
Is it a FK ?(from which No This attribute is not required in any other entities.
table?)
What Data Type has VarChar As part of Student’s Name, varchar is the most
been chosen? appropriate data type.
What Data length has 30 Sufficient length to accommodate almost all the last
been chosen? names without being too long.
Is it Null or Not Null Null Last name can be null as student may not have a last
name
Anything else special It is part of student’s
about this data Item? full name

 Contact phone number for student


Question Answer Provide the reason why you set the data item up this
way – why not another way / another set up?
What is the Column ContactPhone -- Reason not required --
Name in the entity?
Which Entity does the Students -- Reason not required --
Data item belong to?
Is it a PK? (or part of a No Contact phone number can be null, or may not be
PK?) unique
Is it a FK ?(from which No This attribute is not required in any other entities.
table?)
What Data Type has VarChar Contact number will surely contain numbers, but it also
been chosen? can contain spaces, - or + symbols. Therefore, varchar is
the most appropriate data type.
What Data length has 25 Sufficient length to accommodate almost all the phone
been chosen? number lengths exists without being too long.
Is it Null or Not Null Null Contact number can be null
Anything else special
about this data Item?
 Student grade (Pass Fail etc. )
Question Answer Provide the reason why you set the data item up this
way – why not another way / another set up?
What is the Column StudentGrade -- Reason not required --
Name in the entity?
Which Entity does the Result -- Reason not required --
Data item belong to?
Is it a PK? (or part of a No Grade are of limited value, and will not be unique
PK?)
Is it a FK ?(from which No This attribute is not required in any other entities.
table?)
What Data Type has VarChar As per Business Rule
been chosen?
What Data length has 2 As per Business Rule
been chosen?
Is it Null or Not Null Not Null Under the entity results, grade must be present for
each record
Anything else special This data will help
about this data Item? calculating result

 Student date of enrolment (in a specific subject)


Question Answer Provide the reason why you set the data item up this
way – why not another way / another set up?
What is the Column EnrolmentDate -- Reason not required --
Name in the entity?
Which Entity does the Students -- Reason not required --
Data item belong to?
Is it a PK? (or part of a No May not be unique
PK?)
Is it a FK ?(from which No This attribute is not required in any other entities.
table?)
What Data Type has Datetime Most appropriate data type
been chosen?
What Data length has N/A
been chosen?
Is it Null or Not Null Null Null entry is allowed as in special cases, student data
has to be entered before the student is actually
enrolled
Anything else special
about this data Item?
 Subject coordinator
Question Answer Provide the reason why you set the data item up this
way – why not another way / another set up?
What is the Column Teacher_TeacherID -- Reason not required --
Name in the entity?
Which Entity does the Subject -- Reason not required --
Data item belong to?
Is it a PK? (or part of a No This may not be unique for Subject Table
PK?)
Is it a FK ?(from which Yes, from Teacher Unique non null attribute from Teacher Table
table?) table
What Data Type has Int As per Database design.
been chosen?
What Data length has N/A
been chosen?
Is it Null or Not Null Not Null As it is PK in Teacher table
Anything else special
about this data Item?

 Cost of the subject


Question Answer Provide the reason why you set the data item up this
way – why not another way / another set up?
What is the Column SubjectCost -- Reason not required --
Name in the entity?
Which Entity does the Subject -- Reason not required --
Data item belong to?
Is it a PK? (or part of a No This may not be unique for Subject Table
PK?)
Is it a FK ?(from which No This attribute is not required in any other entities.
table?)
What Data Type has Float As per nature of this attribute – it will hold a money
been chosen? value.
What Data length has N/A
been chosen?
Is it Null or Not Null Null In special circumstances, this attribute may need to
hold null value
Anything else special
about this data Item?
 Duration of the subject (in hours)
Question Answer Provide the reason why you set the data item up this
way – why not another way / another set up?
What is the Column SubjectDuration -- Reason not required --
Name in the entity?
Which Entity does the Subject -- Reason not required --
Data item belong to?
Is it a PK? (or part of a No This may not be unique for Subject Table
PK?)
Is it a FK ?(from which No This attribute is not required in any other entities.
table?)
What Data Type has Int As per nature of this attribute – it will hold hour value.
been chosen?
What Data length has N/A
been chosen?
Is it Null or Not Null Null In special circumstances, this attribute may need to
hold null value
Anything else special
about this data Item?

 Quantity of assessment items for the subject


Question Answer Provide the reason why you set the data item up this
way – why not another way / another set up?
What is the Column SubjectAssessQty -- Reason not required --
Name in the entity?
Which Entity does the Subject -- Reason not required --
Data item belong to?
Is it a PK? (or part of a No This may not be unique for Subject Table
PK?)
Is it a FK ?(from which No This attribute is not required in any other entities.
table?)
What Data Type has Int As per nature of this attribute.
been chosen?
What Data length has N/A
been chosen?
Is it Null or Not Null Null In special circumstances, this attribute may need to
hold null value
Anything else special
about this data Item?
 The primary key for the entity that retains the Grade
Question Answer Provide the reason why you set the data item up this
way – why not another way / another set up?
What is the Column Students_StudentID + -- Reason not required --
Name in the entity? Subject_SubjectID
Which Entity does the Result -- Reason not required --
Data item belong to?
Is it a PK? (or part of a Yes Creates the unique value by combining student ID and
PK?) Subject ID
Is it a FK ?(from which Yes (Students table
table?) and Subject Table)
What Data Type has Int As per nature of this attribute.
been chosen?
What Data length has N/A
been chosen?
Is it Null or Not Null Not Null Primary Key
Anything else special Combination of two
about this data Item? Foreign keys
Screenshot of the ERD:

Identifying relationships:
 Students-Result (Result can’t exist without student, also PK of student is part of the PK in
Result)
 Subject-Result (Result can’t exist without subject, also PK of Subject is part of the PK in
Result)
 School-Teacher (Teacher can’t exist without a school)
Non-Identifying relationships:
 Students-School (Independent of each other)
 School-Subject (Independent of each other)

Resitting subjects a second time


I would add another attribute in Result table which will indicate the semester, which will also be part
of the primary key. Introducing semester will allow the student to retake the same subject in
another semester, and by making the semester as part of primary key, I can ensure the
implementation of this business rule.

Q : Provide a query to identify the highest grade for a student in a subject. The student ID is:
000123456, the subject ID is 4DBB (or any other IDs that work in your database)
Ans: SELECT StudentGrade
FROM Result
WHERE Result.Students_StudentID = 1001
AND
Result.Subject_SubjectID =10
ORDER BY StudentResult DESC
LIMIT 1;
A) Provide a query to identify the age of the student in whole years at the time the query is run.
The student ID is: 000123456 (or another ID that works in your database)

SELECT
TIMESTAMPDIFF(year,students.BirthDate,curdate()) as 'AGE'
FROM students
WHERE students.studentID=123456;

This function subtracts the first expression (BirthDate) from second expression (current date). First
expression (Year) or unit tells the function to calculate the result into year value. The function
returns and integer value.

References:

https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html – to know about


functions, and curdate() function

https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_timestampdiff
timestampdiff() function

B) Provide a query to calculate the age of Nancy Davolio, based on her BirthDate in the Employees
table. The output should be in whole years at the time the query is run.

SELECT firstname,LastName,BirthDate,
TIMESTAMPDIFF(year,employees.BirthDate,curdate()) as 'AGE'
FROM employees
WHERE employees.FirstName='Nancy' AND employees.LastName='Davolio';