What are the different types of the Keys available for us in the database to reduce the duplicate records and to handle the null values as well?
Super Key: – It is defined as the key from combinations of the one or more columns or attribute in the table to identify the records very uniquely in the given table. So, depending on the need and situation, we can have any number of super keys in the table.
Candidate Key: – It is defined as the key from one column and combinations of the more than one column or attribute in the table to identify the records uniquely without the need of any external data in the given table. So, depending on the requirement, we can have one or more than one number of Candidate keys in the table. One of them can become the Primary Key. Candidate Key is always be the part of the Super Key. For example:- If we are having a table called the Student, which includes the columns like EmployeeID, EmployeeName, EmployeeDepartment and EmployeeSSN, we can use the EmployeeID and EmployeeSSN columns together as Candidate Key.
Compound Key: – It is also a combination of more than one column to uniquely identify the records in the given table. These columns can behave like simple key as well when they are separate form combination. For example:- We are having the combination of the two tables like Department and Employees. So, if we are using the combination of two columns EmployeeID and DepartmentID to define the records uniquely in the table. Still these columns have their own meaning in their table.
Composite Primary Key: – When Primary Key of the table is the combination of more than one column, then we can call this key as Composite Primary Key. The combinational values cannot be the duplicate at any time. We can have the duplicate values for the individual columns. These columns cannot be called the simple keys. For example:- We may have the situation in our database to identify uniquely the records like FirstName and LastName to solve the problem.
Alternate Key: – It is defined as the key which is the part of the Candidate Key. Where Candidate Key is combination of the one or more column to uniquely identify the records in the table. Let’s think about the Candidate Key combination of the EmployeeID and EmployeeSSN to uniquely identify the Employee. If we are having the more than the one key one of them will be the Primary Key and other will be the Alternate Key. For example: – EmployeeID will be Primary Key and EmployeeSSN will be the Alternate Key.
Unique Key:-It is defined as the key which does not allow the duplicate values of the key. We can also consider the Primary Key as Unique Key if this key does not allow any Null Value to Primary Key or column. Unique identity is always be maintained for the Primary Key columns to eliminate the redundancy or duplicity. Otherwise we are going to have the same records over and over. These kinds of the records always confused our database or services.
Primary Key is defined as the field or set of fields (attribute or set of attributes) which help us to Uniquely Identify the records within the given table. Primary Key does not allow the “NULL Values” and “Duplicate Values”. It means this field will not be getting duplicate values in the table because it is uniquely identifier in the database. For example: – If we are dealing with the Students and their records in the Student table, then StudentID will be representing the uniquely identified records in the given table. It is also known as the PK in short form.
Foreign Key is defined as the field or set of fields (attribute or set of attributes) which help us to find out the referring table. This is also defining the relationship between the Parent and Child tables in the RDBMS. Foreign Key allows the “NULL Values” and “Duplicate Values”. For example: – If we are dealing with the Students and their records in the Student and School tables, Then StudentID will be representing the Foreign Key in the School table, referring the parent table Student. It is also known as the FK in short form.


Leave a Reply