Chapter Contents




Creates integrity constraints on a SAS table

Category: SAS Table

See Also


sysrc=ICCREATE(table-id,icname,ictype,icvalue<, argument-1<, . . . <,argument-3>>>);

contains the status of the operation:
=0 successful
>0 not successful
<0 the operation was completed with a warning
Type: Numeric

contains the identifier for the SAS table, which is returned by the OPEN function. Integrity constraints can be set for a new SAS table only when it is opened in NEW mode. Integrity constraints can be set for an existing table only when it is opened in UTILITY or NEW mode. (Remember that if you open an existing table in NEW mode, the table is replaced without warning.)

Type: Numeric

is the name of the integrity constraint.

Type: Character

specifies the type of integrity constraint to create:

specifies that column values must fall within a particular set, range, or list of values, or that values must meet a condition or be the same as values in other columns in the same row.

specifies that a column is linked to a column in another SAS table. A foreign key column can contain only a null value or a value that is present in the associated primary key column.

specifies that column values cannot contain missing values.

specifies that column values must be unique and that they cannot be missing values. If there is an associated foreign key column, then primary key values cannot be deleted or changed unless the same deletions or changes have been made in values of that foreign key column.

specifies that column values must be unique. If more than one column is specified, then their concatenated values must be unique.

Type: Character

specifies the names of one or more columns from the SAS table to which the constraint is applied. Separate multiple column names with blanks. If ictype is CHECK, then icvalue can contain a condition that values must meet.

Type: Character

are additional specifications that are used when ictype is FOREIGN.

is the name of the SAS table in which one or more associated primary keys are defined. This links the two SAS tables and creates the primary/foreign key relationship. Use libref.member to specify the SAS table. This argument is required for foreign keys.

is the restriction option for update operations on values in foreign key columns:

allows the primary key value to be updated only if no foreign key matches the current value to be updated.

specifies that when the primary key value is modified, all matching foreign key values are set to NULL.

is the restriction option for delete operations in foreign key columns:

allows the primary key row to be deleted only if no foreign key values match the deleted value.

allows the primary key row to be deleted and sets the values of corresponding foreign keys to null.

Type: Character


ICCREATE defines integrity constraints for a SAS table that has been opened in an SCL program. Integrity constraints guarantee the correctness and consistency of data that is stored in a SAS table. Integrity constraints are enforced automatically for each addition, update, or deletion of data in a table that contains a constraint.

You can define integrity constraints for SAS tables that contain zero or more rows. For tables that already contain data, an integrity constraint is compared to values in all table rows. If a single row does not comply with the constraint being defined, then the creation of the constraint fails. When rows are added to tables that have integrity constraints, the new rows are checked against the constraints. If a row violates an integrity constraint, the row is not added to the table. Also, a primary key column cannot be dropped until all foreign key columns that reference the primary key are deleted.

The basic types of integrity constraints are general constraints and referential constraints. The general constraints, which control values in a single SAS table, are CHECK, NOT-NULL, PRIMARY key, and UNIQUE. Referential constraints, which establish a parent-child relationship between columns in two SAS tables, include FOREIGN keys and PRIMARY keys that have one or more FOREIGN key references. A FOREIGN key column (the child) can contain only null values or values that are present in its associated PRIMARY key (the parent). Values for a FOREIGN key cannot be added unless the same values also exist in the associated PRIMARY key.

For more information about integrity constraints, see Preserving the Integrity of Data.


This example creates integrity constraints for the SAS tables MYLIB.ONE and MYLIB.TWO. Although they contain different data, they have one column with shared data, an identifier number that is stored in IDNUM in MYLIB.ONE and in EMPID in MYLIB.TWO. The following icnames are used in the example:
UQ is a UNIQUE constraint which specifies that the concatenated values of columns D and E must be unique.
WH is a CHECK constraint which specifies that the sum of the values of columns B and C must be less than 1000.
PK is a PRIMARY constraint which specifies that the IDNUM column can contain only unique and non-missing values. Because IDNUM is associated with the foreign key column EMPID in the table MYLIB.TWO, values for IDNUM cannot be deleted or changed unless the same changes have been made to the values in the foreign key EMPID.
FK is a foreign key in the table MYLIB.TWO. EMPID is the foreign key column whose primary key is IDNUM in MYLIB.ONE. Because EMPID is a foreign key column, it can contain only values that are present in IDNUM. The first RESTRICT specifies that a value in IDNUM can be changed only if EMPID does not contain a value that matches the IDNUM value to be changed. The second RESTRICT specifies that a row can be deleted from MYLIB.ONE only if the value of IDNUM does not match a value in EMPID in MYLIB.TWO.
NONULL is a NOT-NULL constraint which specifies that the EMPID column cannot contain a null value.

rc=iccreate(table1,'uq','Unique','d e');
rc=iccreate(table1,'wh','Check','(b + c)< 1000');

    ...more SCL statements...

See Also




Chapter Contents



Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.