IBM Books

Changing the primary key when altering a table

Use the Primary Key page of the Alter Table notebook to alter the primary key for your table. A primary key is a column or set of columns that can be used to identify or access a particular row or rows. A primary key is a unique key, that is it is a key that is constrained so that no two of its values are equal. A table cannot have more than one primary key, and the columns of a primary key cannot contain null values.

You can add or drop columns from the primary key or change the constraint name. To drop a primary key column, select the column you want to drop from the Primary key columns box and click on Remove.

Graphic of Controls push button appears here. Graphic of Overview push button appears here.
Figure rule not displayed.

Before you begin...
Figure rule not displayed.

To alter the primary key:

  1. Open the Alter Table notebook.

  2. Click on the Primary Key tab.

  3. Optional: Select a new primary key column.

    1. In the Available columns box, select an additional column or columns that you want to define as primary key columns. You can define up to 16 columns to be primary key columns.

    2. Click on the > push button to move the selected column or columns to the Primary key columns box.

  4. Optional: Change the name of the constraint by typing a new name in the Constraint name field.

  5. If you do not want to make any additional changes to the table, click on OK to alter your table and close the Alter Table notebook. Otherwise, continue on to one or more of the optional tasks.

Figure rule not displayed.

Related information

[ Top of Page | Table of Contents | Glossary | Index ]

[ DB2 List of Books | Search the DB2 Books ]