Name

foreign-key — Define a foreign-key.

Synopsis

<foreign-key foreignTable="foreignTableName"> 
	<column-ref local="localColumnName" foreign="foreignColumnName" />
	... 
</foreign-key>
				

Description

This element define a foreign key used for the table. At least a column reference should be made to a column previously defined in the table and in another table. The column reference attribute local stands for the local column that is foreign key, and the attribute foreign stands for the foreign column that is primary key in the foreign table. The foreign-table attribute define the name of the referenced foreign table.

Content

column-ref

A reference to another column, the local attribute must match a column name in the same table. The foreign attribute must match a foreign table column name. Multiple column-ref elements can be inserted inside a foreign-key element.

Example

Example 13. Foreign Key example

<project name="testProject">
	...
	<metadata>
		<table name="Suppliers">
			<column name="supplier_id" data-type="integer">
				...
			</column>
			...
			<primary-key>
				<column-ref column="supplier_id" />
			</primary-key>
		</table>
		<table name="Supplier_Addresses">
			<column name="supplier_address_id" data-type="integer">
			</column>
			...
			<column name="supplier_id" data-type="integer">
			</column>
			...
			<primary-key>
				<column-ref column="supplier_address_id" />
			</primary-key>
			...
			<foreign-key foreign-table="Suppliers">
				<column-ref local="supplier_id" foreign="supplier_id" />
			</foreign-key>
		</table>
	</metadata>
	...
</project>