Functional Dependency Clarification - mysql

I am in the process of creating a database for a final project (elementary school) and was a bit confused if I was getting my functional dependencies correctly.
Here are a few tables:
Here are my derived functional dependents:
Schools Table:
School_ID -> School_Name, School_Year
Subjects Table:
Subjects, School ID -> School Year, Subject Name
Course_Join_Periods Table:
Course_Period_ID , Course_ID , Grade_Level_ID, Teacher_ID, Grade_Level, School_Year, Grade_Name, Period_ID, School_ID, Subject_ID, Subject_Name -> Period_Class_Name
Do I have anything correct here or should I go back to the drawing board and re-teach myself F.D's?

Determining the FDs is part of analysis, not design. The FDs you have stated could be correct at your elementary school but incorrect or incomplete at mine.

Related

How to design a simple database

I want to model a student, teacher, class relationship. Every student is associated with one teacher (the teacher can have many students). There are only three classes. The way I think of this is that there are three tables:
Student Table -> (student_id, student_name, class_id)
Teacher Table -> (student_id, student_name, class_id)
Class Table -> (class_id, class_name)
I'm not sure how to show the student-teacher relationship within the tables. How would we know which teacher is assigned to which student?
This can be accomplished with some simple joins.
Assuming that you want to find all the students associated with a certain teacher, you would start off by grabbing the row for the teacher. You would then join in the classes that the teacher teaches. Finally, you would join in the students that are in those classes.
This is known as a many-to-many relationship, and is an important concept in databases.
select
t.student_name, -- I suspect this col might actually be named teacher_name
s.student_name,
from
-- Find the classes that a teacher teaches
teacher_table t join class_table c on (t.class_id=c.class_id)
-- Find the students in those classes
join student_table s on (s.class_id=c.class_id)
where
t.student_id = ? -- Again, I suspect this should be "teacher_id"
This is a few more tables than you want, but several of the .NET examples that Microsoft has created revolve around a similar relational database.
Here is a link to that database:
https://msdn.microsoft.com/en-us/library/bb399731(v=vs.100).aspx
In this example, the student and the teacher are both kept in the person table and are related to the course table through two different Joining tables . . student grade and course instructor.
And here is the Contoso University Schema with link:
https://learn.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-a-more-complex-data-model-for-an-asp-net-mvc-application

how to define relationship in access

I want to create a form for dataentry in access. I am confused about defining the tables. I have a Student table, which includes information about student first name, last name, etc.
I have information about technical skills which has different groups (6 groups) programming, languages,banking, etc. Each group has different parts: for example, Programming has 4 parts JAVA, PHP, C, Python.
Languages also have different parts English, German, Spanish, French
Banking has these parts: Risk Management, Project Management
Each student has different skills; first student knows Java, php, German, Project Management
How many tables should I define and how go I relate them to the main Student table?
I would go with the following structure:
tblStudent
ID (PK)
FirstName
LastName
tblStudent_Skill
Student_ID (PK)(FK)
Skill_ID (PK)(FK)
tblSkill
ID (PK)
SkillName
SkillType_ID (FK)
tblSkillType
ID (PK)
SkillTypeName
tblStudent - only information relating to this specific person, name, address, phone, etc.
tblStudent_Skill - linking table to deal with many-many relationship between tblStudent and tblSkill.
tblSkill - specific skills, for example PHP, English, Python, Maths, etc.
tblSkillType - category list for Skills, for example programming, languages,banking, etc.

Exam Result Publishing mysql

Hi I am developing Exam result publishing application. I am using mysql database for this. My table structure are like this here I didn't include other basic tables
table exams
id
name
year_id
semester_id
course_id
level_id
table exam_students
id
exam_id
student_id
exam_type /* regular/partial */
table exam_results
id
exam_id
student_id
subject_id
marks
Here exams table holds a exam information and students are enrolled in that exam and that information is saved in exam_students table and the result are stored in exam_results. These are fine for a regular students(who will sit for all the subjects exam) but how do I manage the students who were failed in some subjects last time and only sit for some subjects this time(partial type)
For eg, let say we have 3 subjects x,y and z and student A failed in y subject in last exam and this time he only sit for y subject and if he get pass mark this time in y subject then we will have to publish the result of student A along with the other subjects marks that he already gained and if he fails in that subject again he have to sit for it next time.
So how do I design table for this kind of logic.
Its hard for me to explain please if somebody know websites link to get the information on this it will be great help for me.
Thanks for your any help and suggestion
You can have one more table named as "Repeaters". In that, you can have attributes like id, exam_id, student_id and one more that is course_id to make you aware that which course he/she is repeating.

Is there a query for this?

Im making a system for a school and I have this mySQL tables. The names are self explanatory:
student: id name course_id
course: id name
subject: id name
subject_course: id subject_id course_id
grade: id type grade
grade_type: id name
I need to check if every student of a certain course has a grade of type X on every subject that is related with that course.
Let's say grade_type = 'written test'. So I need to check if every student of 1st grade has a grade on the written test on EVERY subject related to first grade (example: math, spanish, history, etc). If yes, I do some stuff. If not, another.
Is there a query that can check that? I was thinking on check student by student but I think is less efficient.
This schema doesn't seem to make sense.
Why would course_id be field on student table? My guess is you need a student_course table to represent a many-to-many relationship between students and courses here.
Also, the grade_type table seems kind of trivial and extra overhead with little value. Could type not just be an enum on grade table?

How do I join multiple tables in SQL whose objects will be modeled using inheritance?

For my university assignment I have to design some basic managment system for sicknesses and all for a school. I have decided to model some basic inheritance in the form of
Person --> Student
Person --> Staff
Person --> Guardian
Person (PersonID, FirstName, LastName)
Student (StudentID (Which references the PersonID), ... )
The reason i decided to do this as I modeled this first in UML and had the inheritance in this.
I have another table which stored Incidents which have both StudentID, StaffID and GuardianID. However I was wondering how I would create a join in mysql which would display all three inherited people's names?
e.g.
Student.FirstName Student.LastName, Staff.FirstName, Staff.LastName etc...
How would I do this?
Or am i doing this completely wrong this way?
Thanks in advance.
http://pastebin.com/m263dd7 - Link to my DDL for the tables.
I have no problem with the database design you've described. It's always a bit awkward to model inheritance in SQL, but you've used the least problematic solution.
Here's a query to answer your question about retrieving the names of a student and staff member for a given incident:
SELECT ps.FirstName, ps.LastName, pf.FirstName, pf.LastName
FROM Incidents i
JOIN Students s USING (student_id)
JOIN Persons ps ON (s.student_id = ps.person_id)
JOIN Staff f USING (staff_id)
JOIN Persons pf ON (f.staff_id = pf.person_id)
WHERE i.incident_id = ?;
I'm assuming the Incidents table looks includes columns such as:
CREATE TABLE Incidents (
incident_id SERIAL PRIMARY KEY,
student_id INT NOT NULL,
staff_id INT NOT NULL,
FOREIGN KEY (student_id) REFERENCES Students(student_id),
FOREIGN KEY (staff_id) REFERENCES Staff(staff_id)
);
Realistically, I'd expect some kind of many-to-many relationship between incidents and each of staff and students. Otherwise, an incident can involve only one student and one staff member?
This is not right. You should have a Person class, and other classes would determine that a certain Person is a Student, Staff, etc. What happens if you have a staff person that is also a student? What happens if the Student graduates?
It is a classic example of impedance mismatch between the relational model and the OO model.
You could have for example three tables:
PERSON
PersonId
LastName
FirstName
STUDENT
StudentId
PersonId
STAFF
StaffId
PersonId
I dont know what the real usage, but it is not a good idea to use inheritence just for reusability.
At first sight, having a Person class in a university management system (something similar) does not seem right.
It would be better you mention the objective/purpose of the assignment - what is is supposed to do.