Alter Principal Keys

Applies to: yesSQL Server 2016 (13.x) and subsequently YesAzure SQL Database YesAzure SQL Managed Case

You can alter a primary key in SQL Server by using SQL Server Management Studio or Transact-SQL. You lot can change the primary key of a table by changing the column social club, index name, amassed option, or fill factor.

In This Topic

  • Before you begin:

    Security

  • To modify a primary key, using:

    SQL Server Management Studio

    Transact-SQL

Before You Brainstorm

Security

Permissions

Requires Change permission on the tabular array.

Using SQL Server Management Studio

To modify a primary key

  1. Open the Tabular array Designer for the table whose principal key you desire to modify, right-click in the Tabular array Designer, and choose Indexes/Keys from the shortcut card.

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

  3. Complete an action from the following table:

    To Follow these steps
    Rename the master key Type a new name in the Name box. Make sure that your new name does not duplicate a proper name in the Selected Primary/Unique Key or Index listing.
    Set the clustered pick To create a clustered alphabetize for the primary primal, select Create every bit CLUSTERED, and select the option from the drop-downwards list box. Only 1 amassed index tin be per table. If this option is not available for your alphabetize, you must first clear this setting on the existing clustered index.

    If this option is non selected, a unique nonclustered index is created.

    Define a fill factor Aggrandize the Make full Specification category and type an integer from 0 to 100 in the Fill factor box. For more information nigh fill factors and their uses, come across Specify Fill Gene for an Index.
    Alter the column guild Select Columns, and and then click the ellipses (...) to the correct of the property. In the Index Columns dialog box, remove the columns from the principal key. And then add the columns back in the order you desire. To remove a column from the key, simply remove the column name from the Column name list.
  4. On the File card, click Save table name.

Using Transact-SQL

To modify a primary key

To modify a PRIMARY Primal constraint using Transact-SQL, you must first delete the existing PRIMARY Fundamental constraint and then re-create it with the new definition. For more than information, meet Delete Primary Keys and Create Main Keys.