SAS Component Language Dictionary |
Category: | SAS Table |
Syntax | |
Details | |
Example | |
See Also |
Syntax |
sysrc=ICCREATE(table-id,icname,ictype,icvalue<, argument-1, argument-2, argument-3g<, message<, msgtype>>>); |
contains the status of the operation:
=0 | |
>0 | |
<0 |
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.)
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 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.
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.
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.
specifies that when the primary key value is modified, all matching foreign key values are set to the same value as the primary key.
is the restriction option for delete operations in foreign key columns:
is your own error message that is displayed when a data value fails to comply with the constraint.
Note: The maximum length for the entire message, including both the user message and the system message that may be appended to the user message, is 256 characters. If the user message is too long, either the user message or the system message will be truncated.
controls how the user-defined error message is displayed.
adds the user-defined message to the beginning of the message that is displayed by SAS and separates the two message with a blank. This behavior is the default.
replaces the SAS message with the user-defined message.
Details |
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 Table Data in SCL Programs.
Example |
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:
table1=open('mylib.one','V'); rc=iccreate(table1,'uq','Unique','d e','','','', 'This is my message for uq.','user'); rc=iccreate(table1,'wh','Check','(b + c)< 1000'); rc=iccreate(table1,'pk','Primary','idnum'); rc=close(table1); table2=open('mylib.two','V'); rc=iccreate(table2,'fk','Foreign','empid','mylib.one', 'restrict','restrict','This is my message for fk.','user'); rc=iccreate(table2,'nonull','Not-null','empid'); ...more SCL statements... rc=close(table1); rc=close(table2);
See Also |
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.