Chapter Contents |
Previous |
Next |
ICCREATE |
Category: | SAS Table |
Syntax | |
Details | |
Example | |
See Also |
Syntax |
sysrc=ICCREATE(table-id,icname,ictype,icvalue<, argument-1<, . . . <,argument-3>>>); |
=0 | successful |
>0 | not successful |
<0 | the operation was completed with a warning |
Type: Numeric
Type: Character
'CHECK'
'FOREIGN'
'NOT-NULL'
'PRIMARY'
'UNIQUE'
|
'DISTINCT'
Type: Character
CHECK
, then icvalue can contain
a condition that values must meet.
Type: Character
FOREIGN
.
'RESTRICT'
'NULL'
'RESTRICT'
'NULL'
Type: Character
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 Data.
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:
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. |
table1=open('mylib.one','V'); rc=iccreate(table1,'uq','Unique','d e'); 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'); rc=iccreate(table2,'nonull','Not-null','empid'); ...more SCL statements... rc=close(table2);
See Also |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.