Creating a Foreign Key

Create a foreign key to constrain a column or columns based on column values in another table.

Prerequisites 

Before you can create a foreign key, be sure that the data server containing the table for which you are creating a foreign key is running, and you created and established a connection to the data server.

  1. Expand the Tables folder.
  2. Right-click the table, and select New > Foreign Key .
  3. Specify properties for the new foreign key.
    Field Description
    Foreign Key Name Enter a name for the foreign key in the text field, or leave the field blank for an auto-generated name.
    Database Choose a database for this data server.
    Owner Choose an owner for this data server.
    Table (Optional) Enter a filter expression for the tables to be displayed in the list of available primary tables. For example, * lists all tables for the specified database and owner combination.
    Available Primary Tables Highlight the table that you want this foreign key to reference.
    Primary Key/Unique Constraints Highlight the unique or primary key constraint in the primary table that this foreign key references.
  4. Click Next, and specify column mappings for the foreign key.
    Field Description
    Columns Mapping Highlight the column or columns that you want subject to the foreign key constraint.
    Match Full Specify the constraint conditions on the values of the referencing columns. If all values in the referencing columns of a referencing row are:
    • Null – the referential integrity condition is true.
    • Non-null – the referential integrity condition is true if there is a referenced row where each corresponding column is equal in the referenced table.
    The referential integrity condition is false when:
    • All values are non-null and not equal, or
    • Some of the values in the referencing columns of a referencing row are non-null values, while others are null.
    Preview Displays the DDL for creating the foreign key.
  5. Click Next, and specify save and execution properties for the foreign key.
    Field Description
    Generate Script Generate DDL for the foreign key.
    Enter or Select the Parent Folder Specify an existing project or create a new project in which to save the DDL.
    File Name Enter the name of the file in which to store the DDL.
    Execute Immediately Execute the DDL immediately. If you do not select this option, you must complete execution of the DDL later to create the foreign key.
    Open in Editor After Creation Create the foreign key and open it in the Table Schema Editor.
  6. Click Finish to create the foreign key.
Related concepts
Foreign Keys
Related tasks
Editing Table Schema Data
Creating a Primary Key
Editing a Foreign Key
Dropping a Foreign Key

Send your feedback on this help topic to Sybase Technical Publications: pubs@sybase.com

Your comments will be sent to the technical publications staff at Sybase, Inc. For product-related issues or technical support, contact Sybase Technical Support at 1-800-8SYBASE.