How to create a primary key in SQL Server Table Designer

Developers define a primary key to to enforce uniqueness for values entered in specified columns that do not allow nulls. A table can have only one primary key. Primary keys is used to relate the table in which is defined to other tables in the database. In this way the need for redundant data is reduced. Developers should follow the next steps when they want to create a primary key:

1. In Table Designer, click the row selector for the database column they want to define as the primary key. Developers can select multiple columns, by keeping down the CTRL key while they click the row selectors for the other columns.

2. Right-click the row selector for the column and selects Set Primary Key. A primary key index, named “PK_” followed by the table name, is automatically created; Developers can find it on the Indexes/Keys dialog box.

 

Note: Developers can redefine the primary key, but they must delete any relationships to the existing primary key before the new primary is created. A message will warn him/her that existing relationships will be automatically deleted as part of this process.

A primary key column is identified by a primary key symbol in its row selector. If a primary key consists of more than one column, duplicate values are allowed in one column, but each combination of values from all the columns in the primary key must be unique.