HPlogo ALLBASE/SQL C Application Programming Guide: HP 3000 MPE/iX Computer Systems > Chapter 9 Programming with Constraints

Using Unique and Referential Integrity Constraints

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

Any database containing tables with interdependent data is a good candidate for the use of integrity constraints. You can profit from their use whether your data is volatile or stable in nature. For instance, your database might contain a table of employee and department data that is constantly changing, or it could contain a table of part number data that rarely changes even though it is frequently accessed. (Note that integrity constraints cannot be assigned to LONG columns. LONG columns are described in the chapter, Programming with LONG Columns.)

To implement unique and referential constraints, use the CREATE TABLE command and optionally the GRANT REFERENCES command in your schema file. The following table lists the commands you might use in dealing with integrity constraints.

Table 9-1 Commands Used with Integrity Constraints

DDL OperationsDCL OperationsDML Operations
CREATE TABLEGRANT REFERENCES[BULK] INSERT
DROP TABLEGRANT DBAUPDATE [WHERE CURRENT]
REMOVE FROM GROUPREVOKE REFERENCESDELETE [WHERE CURRENT]
DROP GROUPREVOKE DBA 

 

The concepts and syntax of integrity contraints are fully discussed in the ALLBASE/SQL Reference Manual , and database administration considerations are found in the ALLBASE/SQL Database Administration Guide . This chapter contains techniques to use when coding applications that manipulate data upon which integrity constraints have been defined.

When executing the [BULK] INSERT, UPDATE [WHERE CURRENT], or DELETE [WHERE CURRENT] commands, ALLBASE/SQL considers applicable integrity constraints depending on what the overall effect of a statement would be once it completes execution. The syntax for UNIQUE or PRIMARY KEY requires unique constraint enforcement. The syntax for REFERENCES requires referential constraint enforcement on the referencing and referenced tables involved. For example, consider the following table showing what tests must be passed for a DML command to successfully complete.

Table 9-2 Constraint Test Matrix

DML OperationsUNIQUE or PRIMARY KEYReferenced TableReferencing Table
[BULK] INSERT or Type 2 INSERTMust be unique in the table. Must match a unique key in the referenced table.
UPDATE [WHERE CURRENT]Must be unique in the table.No foreign key can reference the unique key being updated.Must match a unique key in the referenced table.
DELETE [WHERE CURRENT] No foreign key can reference the unique key being deleted.  

 

Feedback to webmaster