Supposed i have a relational table:
FinalYearProject(supervisor, researchTopic, consultationDay, student)
and the following functional dependencies:
student -> researchTopic
student, researchTopic -> supervisor
researchTopic,supervisor -> consultationDay
From there i determined my minimal superkey is: student where
student -> researchTopic,supervisor, consultationDay
Is it right for me to say that there is partial dependency as supervisor do not depend solely on student based on the functional dependency:
student, researchTopic -> supervisor
Any help will be greatly appreciated.
Since student is the candidate key, supervisor depends on it.
In fact, consider that, given student -> researchTopic, the research topic depends on the student: so in the dependency student, researchTopic -> supervisor the attribute researchTopic is superfluous (the depedency student -> supervisor holds). It is easy to show this by using the Armstrong’s Axioms.
And since a relation is not in 2NF when a non-prime attribute is functionally dependent on a proper subset of a candidate key, there is no such case in this example, and the relation is in 2NF.
Related
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
I would like to retrieve the Names of teachers who teach more than 1 course
I am really stuck on how to do it , all I know is that I need to consider the Course schema and operate on it , could I get some advice in terms of pi(projection),sigma(condition),rho(rename) etc (not i any specific database language)?
Since this is homework and you basically need to read & work through a textbook's absolutely introductory text & exercises on relational model basics & the relational algebra, I give some guiding questions tailored to your assignment.
A relation (given or query result) comes with a predicate, ie a statement template parameterized by attributes. A relation holds the tuples that make a true statement from its predicate. PKs & FKs are not needed for querying.
What is a relation expression for the tuples where...
the person identified by teacherid teaches the course identified by cid, which is named name? (Answer: Course.)
teacherid teaches cid named name? (Same answer. Why?)
teacherid teaches cid AND cid is named name? (Same answer. Why?)
(We can infer from your assignment query that the Course & Teacher predicates refer to persons or you couldn't get at teacher names.)
t teaches c named n?
t teaches c named n AND c = 101?
t teaches c named n AND t occupies o?
t teaches some course named some name?
for some c, t teaches c named some name? (Same answer. Why?)
for some c, t teaches c named something AND c = 101? (Why do we need FOR SOME?)
i ids a student AND NOT i takes some course taught by some teacher?
some student takes some course taught by t OR t occupies some office?
Thus: We compose a query predicate for the tuples we want using logic operators and the given predicates. Then we get an expression that calculates them by converting logic operators to relation operators and given predicates to given relations. (It can be tedious rearranging to get two relations with the same attributes in order to use AND NOT (MINUS) or OR (UNION).)
See this.
retrieve the Names of teachers who teach more than 1 course
You want tuples where attribute Name is the name of a person and for some two values the person teaches the first one's course and they teach the second one's course and those values/courses are not the same.
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?
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.
I have a relation
Competitor(PID, EventName, Pname, TeamName, TeamCoach,EventDate, TeamRating).
and I have my FDs
PID -> Pname
PID --> TeamName
TeamName --> TeamCoach
EventName --> EventDate
TeamName, EventName --> TeamRating
which will form into my relations
Competitor(_PID_, Pname, TeamName*)
Team(_TeamName_, TeamCoach)
Event(_EventName_, EventDate)
Rating(_TeamName_*, _EventName_*, TeamRating)
Entry(_PID_*, _EventName_*)
However, since my candidate key is {PID, EventName}, how can the Team relation be in BCNF if TeamName is not even part of the key?
A set of FDs as written down in your question, applies to a single relation schema. The set of FDs as they apply to a given relation schema, determines what the keys will be to that relation schema.
For example, your set of 5 FDs corresponds to the 7-column relation schema that you started with. And that set of FDs allows to determine that the key to your 7-column relation schema is indeed {PID EventName}.
But if you split that 7-column schema in parts, then this has its consequences for which FDs are still applicable, and to which of the parts.
For example. Suppose you single out
Team(_TeamName_, TeamCoach)
and leave
Competitor(PID, EventName, Pname, TeamName, EventDate, TeamRating).
For each of the individual FDs, you now have to decide to which of the two new relation schemas that individual FD applies.
In the example at hand :
Team(_TeamName_, TeamCoach)
TeamName --> TeamCoach
Competitor(PID, EventName, Pname, TeamName, EventDate, TeamRating)
PID -> Pname
PID --> TeamName
EventName --> EventDate
TeamName, EventName --> TeamRating
You now have not only two relation schemas, but also two distinct sets of FDs that apply to them, respectively. The teamname->teamcoach FD now no longer applies to the (revised) Competitor relation schema, but only to the Team schema. This allows you to conclude that TeamName will be a key to the Team schema.
BTW it will not always be possible to retain all the FDs that you started out with. An FD whose overall set of attributes (left-hand side plus right-hand side) is such that after the schema split, there no longer is any relation schema that includes all those attributes, such an FD can simply no longer be expressed, and must be reinstated in the resulting design as a database constraint that does not take on the form of an FD (/key). That is the issue of "dependency preservation".