What are the differences between the Primary Key and Foreign Key? What are their importance and use in the Relational Database Management System (RDBMS)?
Here is the question for us “How to find out the relation among the columns in the same table and relationship between the other tables in the database like SQL Server Database and Oracle Database, DB2 and many more.
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.
For creating the conceptual and logical modeling for the schema and tables, we should know in detail about these Primary and Foreign Keys to get more accurate and meaningful records in the queries.
Here are the different types of the keys in the SQL Server database:
1) Super Key
2) Candidate Key
3) Compound Key
4) Primary Key
5) Composite Primary Key (Composite Key)
6) Foreign Key
7) Unique Key
8) Alternate Key
As per Database Design and Development point of view we should know “Where we can use the Super Key?” “Where we are allowed to use the Candidate, Compound, Composite Key, Alternate Key and Unique Key?”
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.
I will be discussing these keys in detail in the next article. I would like to share some information as I know and I would like to have the feedback for all the readers as well to enhance my knowledge and your knowledge.
This part will be in detail if you click on this link:- 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.
Here is it really important to understand as per the database relationship among the table and their columns. If we are not sure which key is useful for what purpose, then we are not good to understand the structure of the database. Understanding of these Keys is really important for Architectural Design and Development perspective. If we are working as the Database Architect or Developer then we can easy get the information required for display for an application. We can set some constrain for the table and columns.
Thanks,
Sandeep Rajmail


Leave a Reply