Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SAP Sybase SQL Anywhere 16.0 » SQL Anywhere Server - SQL Usage » Tables, views, and indexes » Foreign keys


Creating a foreign key (Sybase Central)

You can create a foreign key relationship between tables. A foreign key relationship acts as a constraint; for new rows inserted in the child table, the database server checks to see if the value you are inserting into the foreign key column matches a value in the primary table's primary key.


You must have SELECT privilege on the table or the SELECT ANY TABLE system privilege.

You must also be the owner of the table, or have one of the following privileges:

  • ALTER privilege on the table along with one of COMMENT ANY OBJECT, CREATE ANY OBJECT, or CREATE ANY TABLE system privileges
  • ALTER ANY TABLE system privilege
  • ALTER ANY OBJECT system privilege

Contexte et remarques

You do not have to create a foreign key when you create a foreign table; the foreign key is created automatically.

  1. In Sybase Central, use the SQL Anywhere 16 plug-in to connect to the database.

  2. In the left pane, double-click Tables.

  3. Select the table for which you want to create or a foreign key.

  4. In the right pane, click the Constraints tab.

  5. Create a foreign key:

    1. Click File » New » Foreign Key.

    2. Follow the instructions in the Create Foreign Key Wizard.


In Sybase Central, the foreign key of a table appears on the Constraints tab, which is located on the right pane when a table is selected. The table definition is updated to include the foreign key definition.


When you create a foreign key by using the wizard, you can set properties for the foreign key. To view properties after the foreign key is created, select the foreign key on the Constraints tab and then click File » Properties.

You can view the properties of a referencing foreign key by selecting the table on the Referencing Constraints tab and then clicking File » Properties.

To view the list of tables that reference a given table, select the table in Tables, and then in the right pane, click the Referencing Constraints tab.

 See also