Table of Contents Previous Next


2 SQL Tutorial : 2.2 Advanced Concepts : 2.2.2 Foreign Keys

Suppose you want to make sure all employees belong to a valid department. This is called maintaining the referential integrity of your data. In simplistic database systems this would be implemented (if at all) by first looking at the dept table to check if a matching record exists, and then inserting or rejecting the new employee record. This approach has a number of problems and is very inconvenient. Advanced Server can make it easier for you.
A modified version of the emp table presented in Section 2.1.2 is shown in this section with the addition of a foreign key constraint. The modified emp table looks like the following:
If an attempt is made to issue the following INSERT command in the sample emp table, the foreign key constraint, emp_ref_dept_fk, ensures that department 50 exists in the dept table. Since it does not, the command is rejected.

2 SQL Tutorial : 2.2 Advanced Concepts : 2.2.2 Foreign Keys

Table of Contents Previous Next