Foreign Keys Wizard (DB2 LUW)

From DBArtisan
Jump to: navigation, search

Go Up to IBM DB2 for Linux, Unix, and Windows Object Wizards

Foreign keys are unique values that refer to specific columns of other tables. Thus, a foreign key links two tables together. The Foreign Key Wizard makes it easy for you to create a relational link between two tables, thereby speeding queries and giving you faster access to data.The Foreign Key Wizard lets you create a foreign key without knowing the underlying commands.

To create a new foreign key using a wizard

  1. Open a creation wizard for a foreign key. For details, see Opening an Object Wizard.
  2. Use the following topics as a guide to setting properties and performing tasks as you pass through the wizard panels:
  3. Finally, use the Execute button to create the object.

Foreign Keys (DB2 LUW) - Properties

When creating or editing a foreign key, this tab/panel lets you work with the following settings:

Setting Description

Table Schema

The schema owning the table where the foreign key is created.

Table Name

The table where the foreign key link originates, otherwise known as the child table.

Name

Lets you select a constraint name.

  • System Generated Name. DB2 automatically generates a name.
  • User Specified Constraint Name. Type the name.

Enabled

TRUE enables the Foreign Key while FALSE disables the Foreign Key.

Delete Rule

Select one of the following actions:

  • NO ACTION. Ensures that you cannot update or delete referenced values if to do so would violate referential integrity.
  • CASCADE. Allows you to update or delete a referenced row in a child table if it is updated or deleted in the parent table. A row in the child table is SET NULL when rows in the parent table are deleted/updated.
  • RESTRICT. Prevents a command from executing if changes to referential data prompts an error.

Update Rule

Select one of the following actions:

  • NO ACTION. Ensures that you cannot update or delete referenced values if to do so would violate referential integrity.
  • RESTRICT. Prevents a command from executing if changes to referential data prompts an error.

Foreign Keys (DB2 LUW) - Column Mapping

To use Column Mapping

  1. Under Referenced Table, choose the Owner and then the Name of the referenced, or parent, table.
  2. Under the Main Table, select check boxes corresponding to the columns that are to reference columns in the referenced table.