User Guide : 7. Working with Tables : Foreign Keys, Indexes, and Constraints : Foreign Key Relationships
 
Share this page                  
Foreign Key Relationships
After you have assigned primary keys (see Assign Primary Keys), you can create foreign key relationships. You define foreign keys using the New Foreign Key dialog (see New Foreign Key Dialog).
Note:  Foreign key functionality is available for Actian Vector tables if the table is newly created and empty.
Preconditions:
An installation must be connected to.
The Keys folder child node of a table node must be selected in the Instance Explorer.
Access route:
From the context menu: New Foreign Key
New Foreign Key Dialog
You use the New Foreign Key dialog to create foreign keys. For more information, see Create a Foreign Key Relationship (see Create a Foreign Key Relationship).
The New Foreign Key dialog contains the following areas:
Name
Specifies the name of the new foreign key
Specification
Lets you specify the tables and columns specifications for the foreign key relationship. Click the browse button (...) to launch the Tables and Columns dialog (see Tables and Columns Dialog) so that you can specify the relationship between tables and columns.
Delete Rule
Selects the delete rule for the foreign key constraint.
Possible values for Ingres databases are:
No Action
Cascade
Restrict
Set Null
The only value possible for Actian Vector databases is Restrict.
Update Rule
Selects the update rule for the foreign key constraint.
Possible values for Ingres databases are:
No Action
Cascade
Restrict
Set Null
The only value possible for Actian Vector databases is Restrict.
The New Foreign Key dialog contains the following controls:
OK button
Creates the foreign key(s)
Cancel button
Closes the dialog without creating the foreign key
Tables and Columns Dialog
The Tables and Columns dialog lets you specify the tables and columns specifications for a foreign key relationship. Clicking the browse button (...) on the New Foreign Key Dialog launches the Tables and Columns dialog so that you can specify relationships between tables and columns.
The Tables and Columns dialog contains the following fields and controls:
Foreign Key to be Added
Displays the name of the relationship that you specified on the New Foreign Key dialog
Target Table
Lets you select a table containing the primary key from a drop-down list of all table names for the current database. Before you can create a foreign key relationship, you must have assigned primary keys (see Assign Primary Keys) during the creation of a table.
Target Constraint
(Read-only) Displays the primary key(s) in the selected target table
Corresponding Foreign Key Columns
Lets you define the specification. Click the drop-downs to choose column names for the current table (the Foreign Key Table).
Save button
Saves the relationship and closes the dialog
Cancel button
Closes the dialog without saving any changes
Create a Foreign Key Relationship
You create foreign key relationships with the New Foreign Key Dialog and the Tables and Columns Dialog. Before you can create a foreign key relationship, you must have assigned primary keys (see Assign Primary Keys) during the creation of a table.
To create a foreign key relationship
1. Drill down through the connected installation in the Instance Explorer, open the Databases folder, and locate the database containing the table you want to create a foreign key relationship in.
2. Open the table node in the Instance Explorer to display its subfolders.
3. Right-click the Keys folder and select New Foreign Key from the context menu.
The New Foreign Key dialog opens (see New Foreign Key Dialog).
4. Enter the name of the foreign key relationship in the Name field.
5. Click the browse button (…) to the right of the Tables and Columns Specification field.
The Tables and Columns dialog opens (see Tables and Columns Dialog).
6. In the Tables and Columns dialog, select a target table containing the primary key.
7. Select a corresponding foreign key column (on the right) for each primary key listed (on the left).
8. Click Save to assign the relationship and close the Tables and Columns dialog.
9. Specify a delete rule for the foreign key relationship.
10. Specify an update rule for the foreign key relationship.
11. Click OK.
Delete a Foreign Key Relationship
You delete foreign key relationships with the Delete Key dialog.
To delete a foreign key relationship
1. Drill down through the connected installation in the Instance Explorer, open the Databases folder, and locate the database containing the table from which you want to delete a foreign key relationship.
2. Open the table node in the Instance Explorer to display its subfolders, and open the Keys folder.
3. Right-click the key node you want to delete and select Delete from the context menu.
The Delete Key dialog opens.
4. Select the foreign key to delete.
5. Set the type of update for the deletion: Restrict or Cascade.
6. Click OK.
The foreign key relationship is deleted.