Is it mandatory for a table to have primary key?

Is it mandatory for a table to have primary key?

Every table can have (but does not have to have) a primary key. The column or columns defined as the primary key ensure uniqueness in the table; no two rows can have the same key. The primary key of one table may also help to identify records in other tables, and be part of the second table’s primary key.

Can a table have a primary key that is not clustered?

A table can have a primary key that is not clustered, and a clustered table does not require a primary key. So the answer to both questions is yes. A clustered index stores all columns at the leaf level. That means a clustered index contains all data in the table. A table without a clustered index is called a heap.

What is the relationship between a clustered index and a primary key?

That means a clustered index contains all data in the table. A table without a clustered index is called a heap. A primary key is a unique index that is clustered by default. By default means that when you create a primary key, if the table is not clustered yet, the primary key will be created as a clustered unique index.

Do I need to include the primary key in an index or not?

Non-clustered indexes implicitly include the clustered index keys automatically. So if your primary key is clustered (not a requirement), you do not need to explicitly include in non-clustered indexes. The INCLUDE option is basically to facilitate creation of covering non-clustered indexes without adding columns to the key itself.

Do you need to include in non clustered indexes?

So if your primary key is clustered (not a requirement), you do not need to explicitly include in non-clustered indexes. The INCLUDE option is basically to facilitate creation of covering non-clustered indexes without adding columns to the key itself. Dan Guzman, SQL Server MVP, http://www.dbdelta.com Thank you both.