How to: Modify Primary Keys

Modify a primary key if you want to change the column order, index name, clustered option, or fill factor.

Note

A new version of Table Designer appears for databases in the SQL Server 2012 format. This topic describes the old version of Table Designer, which you use with databases in earlier formats of SQL Server.

In the new version, you can change a table definition through a graphical interface or directly in a script pane. If you use the graphical interface, the table’s definition is automatically updated in the script pane. To apply the SQL code in the script pane, choose the Update button. For more information about the new version, see How to: Create Database Objects Using Table Designer.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Customizing Development Settings in Visual Studio.

To modify a primary key

  1. Open the Table Designer for the table whose primary key you want to modify, right-click in the Table Designer, and choose Indexes/Keys from the shortcut menu.

  2. In the Indexes/Keys dialog box, select the primary key index from the Selected Primary/Unique Key or Index list.

  3. Complete an action from the following table:

    Note

    Some databases have different functionality for primary key constraints. Consult your database documentation for details about how your database works with primary key constraints.

    To

    Follow these steps

    Rename the primary key

    Type a new name in the Name box. Make sure that your new name does not duplicate a name in the Selected Primary/Unique Key or Index list.

    Set the clustered option

    Select Create as CLUSTERED, and select the option from the drop-down list box. Only one clustered index can exist per table. If this option is not available for your index, you must first clear this setting on the existing clustered index.

    Define a fill factor

    Expand the Fill Specification category and type an integer from 0 to 100 in the Fill factor box. For more information about fill factors and their uses, see the Microsoft SQL Server documentation.

    Change the column order

    Select Columns, and then click the ellipses (…) to the right of the property. In the Index Columns dialog box, remove the columns from the primary key. Then add the columns back in the order you want. To remove a column from the key, simply remove the column name from the Column name list.

The primary key is updated in the database when you save your table.

See Also

Tasks

How to: Delete Primary Keys

How to: Change Relationship Properties

Reference

Primary or Unique Key Properties

Concepts

Primary Keys (Visual Database Tools)

Other Resources

Working with Constraints

Working with Constraints