Creating a Foreign Key

Create a foreign key to constrain a column based on values in a reference table.

A foreign key is a column or combination of columns that have values that match the primary key. A foreign key does not need to be unique. It is often in a many to-one relationship to a primary key. A foreign key may be null; if any part of a composite foreign key is null, the entire foreign key must be null.

  1. In the Perspective Resources view, select the server on which the table resides, then click the drop-down arrow next to the server name and select Administration Console.
  2. In the left pane of the Administration Console, expand ASE Servers > Schema Objects > Tables, then choose one of the following:
    • User Tables
    • Proxy Tables
  3. Select the table for the new foreign key.
  4. Select Properties.
  5. From the Table Properties window, select Foreign Keys > New.
    You see the Add Foreign Key wizard.
  6. In the Referenced Table window, select the database that contains the table that the foreign key references.
  7. In the Referenced Column window, select the column that the foreign key references.
  8. Select the referenced table, then specify a name for the foreign key.
  9. Select columns from the Foreign Key Column to match to columns in Primary Key Column.
    Foreign key values should be copies of the primary key values. No value in the foreign key should exist unless the same value exists in the primary key.
  10. (Optional) Click Summary to verify your selected options.
Related tasks
Creating a Check Constraint
Creating a Unique Constraint
Creating a Primary Key
Binding Defaults and Rules to a Column