By definition, primary keys must contain unique data. They are implemented in the database through the use of a unique index. If there is not already a clustered index on the table, then the primary key's index will be clustered. It's not always true, but most of the time, you want your primary keys to be clustered because it is usually the key criteria in your requests to the data. This includes join conditions and where clause criteria. Clustered indexes give you exceptional performance because it allows SQL Server to create optimal execution plans.
How to detect this problem:
- SELECT AllTables.Name
- FROM (
- SELECT Name, id
- FROM sysobjects
- WHERE xtype = 'U'
- ) AS AllTables
- LEFT Join (
- SELECT parent_obj
- FROM sysobjects
- WHERE xtype = 'PK'
- ) AS PrimaryKeys
- ON AllTables.id = PrimaryKeys.parent_obj
- WHERE PrimaryKeys.Parent_Obj IS NULL
- ORDER BY AllTables.Name
How to correct it: Identify tables without a primary key using the query above. Examine each table and identify what makes each row in the table unique. Modify the table to include a primary key.
Level of severity: Moderate
Level of difficulty: Easy



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.