Transcript for:
Understanding Functional Dependency in Databases

In this lecture, we will talk about functional dependency. What is functional dependency? How to find out functional dependency from a given table or relation? Or you can say whatever is given that is functional dependency or not. To check that is functional dependency or not. See, this is very important topic for the point of view of normalization. If you get it, what is functional dependency, the basics of functional dependency very well, then you can easily get the normalization concept, all the normal forms. If you are not good, if you don't know what is functional dependency, how to check out that this is functional dependency or not, or you can say how to write down functional dependency of a table, then you will never get the concept of normalization or the normal forms. Right. So now we will discuss what is functional dependency in this video. With a small example and after that I will discuss with a complete example we will discuss all the functional dependencies from that table. We will draw functional dependencies from that table right with the help of proper example. See here functional dependencies basically you know we represented something like this. with the help of an arrow right if i say see as the name suggests functional dependency means dependency some something is dependent on another thing or some attributes are dependent on another attributes like this right now if i say x determines y let us suppose i am taking a simple example i am taking one relation or you can say one table there i have only two attributes right these are having some values. This is a relation R or a table. Right? Now, if I write the functional dependencies X to Y means X determines Y. It means if I tell you value of X, then from this table you can search value of Y. See here X determines Y doesn't mean that I give you the value of X and you will compute the value of Y. something like this. See, suppose y is equal to x square plus 5x. So, now y is dependent on x and if I give you x is equal to 5, then you can tell me what is value of this y. That would be 50. Here, we are computing the value of y by putting value of x here, right? Functionally dependent. This y is functionally dependent on this x. But in this case, here in the case of DBMS, I am discussing functional dependency. In this case, this is not not a case here you I am just give give you I just give you the value of x and you can search value of y from the table it's not like that you don't have you don't have any table and I'll tell you a value of x and you will tell me value of y by calculating or by computing something no for this you need a table from the table according to value of x you can tell me value of y right that is you can say a functional dependency It means y is you can say functionally dependent on x or you can say x determines y. Fine. So here x is known as determinant and y is known as dependent. Now let us fill this table with some values and then we will see in this table this functional dependency exist or not. You need to follow some rule to check that this is a functional dependency or not in this table. Right. I will tell you all the rules. Now let us take in this table I have these values x value is 1, 2, 3, 4, y value is this one this this this right. Now see if I tell you if I tell you that value of x is 2 now according to 2 tell me what is value of y from this table obviously we will search value of y from this table and the searching would be based on some rules see now what are those rules I am saying value of x is 2 now can you tell me value of y. find out where is x value 2 value of y is 1 yes i can tell you value of y is 1 right now suppose here i have inserted one more that row that is this one 2 and 5 now if i say value of x is 2 now tell me value of y from this table search what is value of y now x is 2 y value is 1 but again i have x is 2 and y value is 5 Now which value you are going to tell me 1 or 5 I cannot say So this cannot be a case See the same example If y is equal to x square Right and x is equal to 5 I am taking Right So now for x is equal to 5 5, y is equal to 25, right? x is equal to 5, y is equal to 25. If I write x is equal to 5, y is equal to 35, then definitely it would be wrong. That is not that cannot be a case right when you functionally compute a value right this is related to this thing here we are not computing but we are searching but the that logic is same now X 5 X 5 then at the both place Y Y should be 25. It cannot be 35. If X value is same, Y value should be or you can say must be same. I hope you are getting my point. Right. So here X value is 2 and 2. So Y value must be either 1 and 1 or 5 or 5. Right. It cannot be a case that here Y value is 1 for this 2 and for this 2, Y value is 5. So here we cannot say. say that x determines y because obviously x cannot determine y in this case if i because on the base of x you cannot tell me value of y then how can you say that x is determining y we cannot say so this is not a functional dependency in this case right if this is the case fine now see here second case may be there if i am taking x is equal to minus 5 then also y is 25 right but vice versa is not true if y is equal to 25 right and in two tuples y is 25 25 it doesn't mean that x should be same. that X should be 5 here for X minus 5 also I can get y 25 this case also we will discuss with proper example right now for now just keep in mind this thing if X value is same in two rows or in two tuples then Y value should be same Y value must be same now see this table is there I have removed that row now if I say X value is 4 tell me value of Y can you tell me yes X value 4 no repetition of 4 is there in this X so I can tell Y value is 3 right same example like in my class I have 60 students and obviously name of sorry the row number of every student is different right For the unique identification, roll number is there. Now, if I say roll number 15, tell me your name, then obviously only one student is having roll number 15, right? Means with the help of roll number, I can determine each student of my class. But now suppose in a seminar hall, I'm taking a class and there I have student of CS as well as EC department, right? Now there, if I say roll number 15, tell me your name. then I cannot determine with the help of roll number that the name of the roll number 15 is what because in CS also there would be roll number 15 in EC also there would be roll number 15 yes suppose in CS I have 60 student there also I have 60 students right so here I cannot determine with the help of roll number so here roll number determines name is not a functional dependency right but in previous case it was functional dependency so it depends based on the relation whatever relation you have based on that relation you need to find out functional dependency right now formally how to write down the definition of this functional dependency see functional dependency x to y means x determines y this is true on a relation if see i'm taking the case here i have 2 and here i have 5 now see here x determines y that is not true because x value is is 2 but y value is here 1 here 5 if here i can write 1 then this would be a functional dependency right so now if in two tuples like t1 dot x equal to t2 dot x fine here t1 and t2 means any two tuples and x means x values like suppose i am taking this tuple and this tuple t1 dot x t1 dot x is 2 t2 dot x t2 dot x is also 2 right if this This is a situation. See, this is not an assignment operator. This is I'm comparing the values. Right. Then y value must be same. Right. Same case here. Y x square x is 5. Then y is 25. Again, I'm writing if x is equal to 5, then y must be 25. Right. That is true. But here, if I write 35, then that is wrong. That is not a functional dependency now. Right. So now, then. Thank you. t1 dot y equal to t2 dot y this should be a case then only you can say that x this is a functional dependency x to y this is functional dependency on this relation right now here check if this is the table then i'm taking any two tuples suppose i'm taking this tuple first of all t1 and t2 right now check if t1 dot x t1 dot x is 1 t2 dot x t2 dot x is 2 is this true no in that case if this is not the k this is not true on the two for the two tuples you are checking then no need to check for y value y value may or may not be same right see here you can say y value is same but it doesn't matter because if this is the if this is true then only we will take this condition then only this This must be true. But it's not like that. If this is false, then it must be false. Or if this is false, then it may be true, it may be false. V does not check this condition if this condition is false. Right? So, here we will not check y values. Right? Now, suppose I am taking these two tuples, 2 and 3. Now, value is 2. In this tuple, value is 3. Is the same? No, we will not check y value. Now, check. For example, for this tuple this one and this one this is suppose t1 this is 2 t2 t1 dot x value is 2 t2 dot x value is 2 now this condition is true because both are 2 now you must check this condition now check t1 dot y t1 is this t1 dot y is 1 is equal to t2 dot y t2 is this row t2 dot y is 5 because this condition is not true in this case right so this is not a functional dependency here i hope you got my point point suppose I am writing this one now can I say this functional dependency exist in this relation yes because see x determines y means check out for any two tuples any two tuples check out value of x for this and this value of x is not same so we are not bothering about value of y will not check for this and this values are not same for this and this values are not same for this and this values are not are not same right. means no value of x is repeating in this case. If the value of x is repeating, then only we care about the value of y. But here every value of x is unique. So this would definitely be a functional dependency. If every value of x is unique, then definitely we can determine value of y from x. The same case, if in my class roll number are different, so every... student is having different roll number so definitely I can identify the name of student from the help of roll number name may be same or not see roll number is 14 roll number is 15 right suppose both are having name Nisha But I don't care about this because I have what? Roll number 14 and 15 to identify if I say 14 then She'll say yes ma'am. If I say 15 then she'll say yes ma'am Right. It means with the help of roll number I can determine each So yes, there is a functional dependency from row number to name. Now one more point here this x and y here I am taking x and y only one attribute. But x and y can be set of attributes. There can be one attribute. attribute two attribute three four five right so these are set of attributes this is very important concept very important point right now let us discuss the functional dependency with the help of a proper example i am taking a proper relation i hope you got what is functional dependency fine now let us take this relation the name is student having five attributes roll number name marks department and course and having six tuples or six records you can you can say right now we will check if you get what is functional dependency and why i am writing this thing i hope you got it very well now you can easily tell me if whatever i am writing that is functional dependency or not in this table right now suppose if i am writing that rollamber determines name now check with the help of this formula whatever we have derived right now check for each for any two tuples right first of all i am taking this tuple and this tuple t1 and t2. t1 dot x here this is x this is y now right. So now value is 1 t2 value is 2. So this condition is not true. So do we need to check this. This condition, no, we don't bother value of this name may be same or not. I don't care, right? Now, check. Suppose this is the tuple, t1 and t2. Now, here also t1 value of x is 2. Here we have 3. so no need to check value of y for this also for this also for this also now here you can see if there is no repetition now see by looking at this database only i can say that in roll number i don't have any repetition right so no two tuples will have same row number value so no need to check for Y value no need to check for name I can say that definitely it is a functional dependency right if repetition is there if this is a case then only we will check this condition right now suppose I am writing here name determines raw number now check is this a functional dependency or not now here this is x this is y right now you need to take care check this is x means take two tuples this two tuple i am taking so value of this x for this one is a this is b values are not same so we don't bother about raw number now check for this for this and this values are not same now see this value and this value is same so here i got repetition Now just check for the repetition values right that would be very easy for you. Now for this tuple the name is a for this tuple name is also a. Now you can easily check you can easily say that this condition is true now. So this must be true. Now check value of y. Now here y is row number right is 1. For this tuple value of y is 3. So this is not true. It means this is not a function. functional dependency. Now see I am taking suppose roll number determines marks. Now see I can see that roll number is x now this is y. So no two tuples of roll number is having same value means no repetition is there in the roll number. So definitely it would be a functional dependency. No need to check for y values right. Now if I say department determine course. Now it means I have I will tell you value of department and can you tell me what is the course from this table? Can you search the course? Now if I say department is CS. Now see department is CS. Now here course is C1. But again department in another tuple is CS but here course is C2. So which one you will tell me C1 or C2? Right. I cannot tell. So this you can you can say this is not a functional dependency. Fine. Or same with help of this formula you can check. this is x this is y so check out the tuples which are having repetition this and this is having repetition this is having same value now for this check the value of y here we have c1 here we have c2 but value of y should be same so this is not a functional dependency here right now if i write course determined department check if i if i say you course is c1 now tell me the department corresponding to that that now course is C1 right department is Cs but course is C1 here department is double E so that is confusing what should I tell you Cs or E right same you can check now this is X this is Y using this formula now take these two tuples T1 and T2 T1 dot X is C1 T2 dot X is C1 so this condition is true if this is true then you will check the Y value now check this is Y now T1 dot Y is Cs T2 dot Y y is e now this is not true because these are not same so this cannot be a functional dependency now you guys will tell me is this a functional dependency or not marks determines department from this relation right now i have told you the x and y x and y may be set of attributes here i'm taking only one one attributes in x and y now suppose i am taking set of attributes see now let us check roll number and name I am taking both determines marks. Is this a functional dependency or not? Now x is having two attributes. Now see the combination of these two. Consider it as a 1. Means this is what x now. And this is what y now. Right. Now see. Rollamber and name. So now see. From here I can easily tell rollamber is not repeating. So definitely the rollamber and name combination will not repeat. if here I again write 1 right and here I write a then there would be a case that if I take this tuple and this tuple then combination is 1 a hair also combination is 1a then this is true now you have to check for marks hair marks is 78 hair marks suppose i'm taking 90 so this is not a case means hair marks are different so this is not a functional dependency if I am writing here 78 again right so now only in the two tuples I have repeating values no other tuple is having repeating value so for this only you need to check marks are same so this is a functional dependency right but in this case no repetition is there in roll number so definitely there would be no repetition in here so definitely it would be a functional dependency now check if I say you Name determine marks. Is it a functional dependency in this case? Now check. Name, if I say name is A, now tell me the marks. From this table, check. The name is A, mark 78. But again I have name A. A marks is also same 78. So it doesn't matter this you will tell or this you will tell right because name is same and marks are also same. So now this is you can say functional dependency. Like same in B and B. Name is same in two tuples. X value is same. Y value is also same. Right. Again, we don't have now any repetition because here I have C, here I have D. So no need to check here. See here Y value is same, but X value are not same. So if X value is not same, then we will not check Y values. It may or may not be same. Right. So this is a functional dependency in this case. See, let us take this example. Say two students in my class are having name Nisha and both. both students are having same marks. So if I'm recording their marks in my register and if I call the name Nisha tell me your marks then obviously both are having same marks so both will tell 78 so there would be no problem like either this will she will tell or she will tell there would be no problem. Problem comes when one is having mark 75 one is having 78 now I'll say Nisha tell me your marks. Now suppose I'm asking marks of this one and And she this she will say 78. So I can record her mark 78. That would be a problematic situation. Right. So this is the case here. Same. Now suppose I am taking name marks determine department. Is this a functional dependency or not? Now this complete is what x and this is what y. Now name and marks. Name and marks. This complete. Suppose take any. any two tuples check out the values suppose this and this here combination is a 78 here b 60 so the value of x for two tuples is not same no need to check y value we don't care about y value now here i'm taking suppose this tuple and this tuple now see a 78 a 78 value is same x value is same now check value of y i'm i want to determine department now department is cs for this also it is cs no problem. Now this and this combination is also same B60 B60. Now department EEE no problem. Now we do not have any repeating combination of name and marks right. So now this is also functional dependency in this table. Now if I am taking here name department determines department sorry name marks determines department course. Now this complete is X. Now this is Y right see now X and Y are having set of attributes now how to check this type of dependency name and marks name and marks see the combination now only check the combination which is repeating see the in this tuple combination in this tuple the same combination so I am taking these two tuples right for these two tuples check the value of Y now if X value is same check the value of Y Y is now department and course department course both now both are Y right now Now you need to check the combination. Here CS and C1 for this tuple and for this tuple CS and C2. Although CS is same but here we have C1 here we have C2 and here Y is complete this one. So this is not same this is same but Y value is not same. So you can say this cannot be a functional dependency right. See here now if for any one combination See here for this and this right I have checked only for T1 and T2 for one combination and this combination is not same so I can say this is not functional dependency no need to check for further if you found one that is violating this condition if this is true but this is not true then you can say at that time only that there this is not a functional dependency. So now I hope you got what is functional dependency and how to find or how to check if a particular given is functional dependency or not on this. on that table right now I'll give you some practice problems and you can check out so you can check these are functional dependencies or not on this relation right and if you want you can tell me in the comment box or if you will not tell me in the comment box then you can practice these that would be enough for me right now in next video I'll discuss types of functional dependencies and properties of functional dependencies or you can say Armstrong axioms fine So now I'll see in the next video till then bye bye take care