What is difference between primary
key and candidate key is another popular SQL and database interview
questions which appears in various programming
interviews now and then. Concept of primary key and candidate key is not
just important from interview point of view but also on designing database and
normalization. By the way this is my second post in primary key, In last one we
have seen comparison of primary
key vs unique key, which is also happens to be one of the frequently asked
database question. By definition primary key is a column or collection of
columns, which uniquely define a row in a table. Candidate keys are keys which
can be primary key and also able to uniquely identify any row in table. In
simply terms you may have couple of Candidate keys and you have choose one of
them as primary key. This selection part is the most important skill in
database design. Since only primary key can have clustered index in table while
unique keys can have Nonclustered index, its important to choose right column
or collection of columns as primary key. Often I select a column which is most
frequently used in Where clause of SELECT query. If you preparing for SQL
interview or looking for some good SQL interview question than you can also
check difference
between Correlated and Noncorrelated subqueries and When
to use truncate vs delete in SQL.