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

SQL Anywhere 11.0.0 » UltraLiteJ » UltraLiteJ Reference » UltraLiteJ API reference

 

ForeignKeySchema interface

Specifies the schema of a foreign key.

Syntax
public ForeignKeySchema
Remarks

An object supporting this interface is returned by the Connection.createForeignKey(String) method.

All foreign keys must have at least one column reference. The set of referenced columns must be columns in the primary table and the set must be subject to a primary or unique key constraint on the primary table.

The following example demonstrates the creation of the schema for a simple database. The Invoices table has a foreign key into the Products table, which specifies that all invoices should reference valid product IDs.

TableSchema table_schema;
IndexSchema index_schema;
ForeignKeySchema fkey_schema;

table_schema = conn.createTable("Invoices");
table_schema.createColumn("inv_id", Domain.INTEGER);
table_schema.createColumn("quantity", Domain.INTEGER);
table_schema.createColumn("sold_prod_id", Domain.INTEGER);

index_schema = table_schema.createPrimaryIndex("primary");
index_schema.addColumn("inv_id", IndexSchema.ASCENDING); 

table_schema = conn.createTable("Products");
table_schema.createColumn("prod_id", Domain.INTEGER);
table_schema.createColumn("prod_name", Domain.VARCHAR, 40);

index_schema = table_schema.createPrimaryIndex("primary");
index_schema.addColumn("prod_id", IndexSchema.ASCENDING);

fkey_schema = conn.createForeignKey(
    "Invoices", "Products", "InvoiceToProduct" );
fkey_schema.addColumnReference("sold_prod_is", "prod_id");

conn.schemaCreateComplete();
Members

All members of ForeignKeySchema, including all inherited members.


addColumnReference function