Some Differences are given below.
1) Both Primary and Candidate keys can uniquely identify records in a table on database.
2) Both Primary and Candidate keys are has constraints UNIQUE and NOT NULL.
3) Primary key or Candidate keys can be either single column or combination of multiple columns in a table.
Now from interview point of view here is difference between Candidate key and primary key in SQL table on point format for easy to remember :
1) There can be multiple Candidate keys in a table in relation database e.g. Oracle, MySQL, Sybase or MSSQL but only one primary key is permitted.
2) An example of Primary key and Candidate key can be ID and SSN number in a Employee table, Since both can identify each employee uniquely .They are candidate key and any one can become primary key. Now if you have to choose between them as primary key, I will go ID as primary key because SSN is sensitive information and may not be allow/not safe to use as String in queries as frequently as ID. Second reason of choosing ID over SSN as primary key can be use of ID as primary tracking ID within organization and its frequent use all over the place. Once you choose a primary key,
3) All candidate key are like unique keys.
1) Both Primary and Candidate keys can uniquely identify records in a table on database.
2) Both Primary and Candidate keys are has constraints UNIQUE and NOT NULL.
3) Primary key or Candidate keys can be either single column or combination of multiple columns in a table.
Now from interview point of view here is difference between Candidate key and primary key in SQL table on point format for easy to remember :
1) There can be multiple Candidate keys in a table in relation database e.g. Oracle, MySQL, Sybase or MSSQL but only one primary key is permitted.
2) An example of Primary key and Candidate key can be ID and SSN number in a Employee table, Since both can identify each employee uniquely .They are candidate key and any one can become primary key. Now if you have to choose between them as primary key, I will go ID as primary key because SSN is sensitive information and may not be allow/not safe to use as String in queries as frequently as ID. Second reason of choosing ID over SSN as primary key can be use of ID as primary tracking ID within organization and its frequent use all over the place. Once you choose a primary key,
3) All candidate key are like unique keys.
No comments:
Post a Comment