Types Of Keys :
1: Primary Key
First type of key is a primary key. We all know it actually we all have heard about it we all have studied about it so just a revision of all the keys so the primary key set of one or more attributes so it can be a single attribute or it can be a set of attributes of a relation that uniquely identify recall any database for example suppose we have a student database so which attribute the databases student so which attribute of the student would uniquely identify the student it would be either the roll number or the registration number so the roll number would be the primary key or the registration number would be the primary key a single student can have two different students can have single name suppose they can be a student called Rekha and they are recovery or there can be another students having recovery but the roll numbers would be always be different so it would be the primary key so what what is it the duplicate values could not be there and it should not accept null value that is for roll number there should be some value the blank value should not be there so the four primary key the first thing is it should uniquely identify the attribute okay. It would be uniquely identifying the attribute this is the first thing the second thing is it should not accept null values and the third thing is it should not accept duplicate values so you can remember these things about the primary key now the line is there only one candidate key can be a primary key.
2: Unique Key
Second is the unique key so there is a similarity between the primary key and the unique key see the four for the primary key. We learned three things that it is you not uniquely identify record so for the unique key also it is the same it must uniquely identify the record okay. The next thing is for example take the address okay so address for each student would be different so it would uniquely identify the student in a single classroom okay but it is like a primary key in this case that is it uniquely identifies a record but it can accept null values and it cannot have duplicate values so the thing is it should uniquely identify a record so it cannot have duplicate values it is similar to the primary key only but it can accept null values so this is the main point the unique key the primary care unit key there is only one difference primary key. It cannot accept null value and the unique key it can accept null value so these are almost similar but they are not same because unique key it cannot have duplicate values. It is similar to the primary key only but it can accept null values whereas the primary key it cannot accept null values let's go to the next key that is an alternate key alternate key is a key that can work as a primary key so alternate key means it is alternate to the primary key basically it is a candidate key that is not a primary key so here also we have the term candidate key we'll go through it what is a candidate key? so it is everything already it can work as a primary key that means the property of the alternate key is it should uniquely identify okay it should be unique the second should be no it cannot have null values not null the values cannot be null and it cannot have duplicate values okay so it is the all the properties of the alternate key would be equal to that of the primary key the next one is the candidate key so the candidate key is what it is also a set of one or more at buttes it can be single attributed alt can you multi or double click the first thing it it just unique it uniquely identifies a table and it can be there can be multiple candidate key in one table and each candidate key a can work as a primary key so every candidate can key can be a primary key and every candidate key can be a alternate key so from the candidate key will get alternate keys and from the alternate keys will get the primary keys so the properties of talented key would be is the same that is it should be unique it should be not null and it should be not duplicate it should not have duplicate values okay so it is similar to primary key.we can say every candidate key can be a primary key for example of in our previous example we said roll number and registration number are both they are both have unique values and both cannot have null values and both cannot have duplicates so but one only one can be the primary key either we can take roll number as a primary key or registration number as a primary key when these both keys are there these both are the candidate keys out of these candidate key one key would be chosen as the primary key
3: Super Key
Super key set of one or more keys on or more than one keys that can be used to identify record so you can say that the super key is a super set it is the super set of what it is a super set of primary key it is a super set of candidate keys and it is the super set of unique key and alternate key so till now whatever keys we have read super key is the super set of all keys.
4: Composite Key
A key with one attribute is a single key okay. Composite key is a key which contains more than one attributes more than one field or columns or more than one attribute it is a composite kid can be candidate here primary key suppose one is not a role role number alone. Suppose it cannot express role number alone is sufficient to be a but what a port if we combine name with date of what name alone is not a primary key data but alone is not a primary key but we combine name and date of birth it can become a primary key so this is actually what it is called it is a composite key that it contains of two attributes name and date of birth so any key which has more than one attribute had called a company composite key or it can also be called as the compound key okay the next is the foreign key a foreign key is a field in the database that is primary key to the another table suppose we have two tables table 1 and table 2 so the primary key of primary key of table 1 which will act as a foreign key of table 2 for example table 1 as a student database and stable 2 is of teacher database okay so that there would be some serial number for teachers or there would be some employee number for teachers okay so in this table suppose for student the this student is taught by the particular teacher X 1 so the employment number in this table it would be a primary key a key of the teacher table it would be used as a foreign key in the student table or the enrollment number of the student can be used as in foreign key in teacher table so this is the foreign key so till now we had read how many keys you can go through all of them first as a primary key second as the unique key third one was the alternate key then it we had the candidate key then we had super keys that we had composite keys and then at last we had the foreign key so this was all I bought the key is in database management system hope you liked.