You can use the DB–Access Schema Editor to define constraints for columns in a specified table. You can define primary-key, foreign-key, column-level and table-level check, and unique constraints, as well as add and modify column default values.
If you select the Constraints option from the CREATE TABLE menu, the CONSTRAINTS menu appears, as Figure 75 shows.
CONSTRAINTS - mytab: Primary Foreign Check Unique Defaults Exit
Define a primary key constraint.
-----------------mydata@mydbserv------a-------- Press CTRL-W for Help --------
The CONSTRAINTS menu has the following options.
To add, modify, or delete primary-key constraints for the current table, select the Primary option on the CONSTRAINTS menu. The PRIMARY KEY menu appears, as Figure 76 shows.
PRIMARY KEY mytab: Add Modify Drop Screen Exit
Add a constraint name or column name.
-------Page 1 of 1 --------mydata@mydbserv------- Press CTRL-W for Help --------
Constraint Name Column Name
constraint1 column1
When you enter a primary constraint, DB–Access validates your entry by verifying the following information:
Use the menu options as follows:
If you press RETURN in this field without typing a constraint name, the database server assigns a temporary constraint name, such as unassigned1, unassigned2, and so on. This temporary constraint name exists until you modify it or the table is built or discarded. The database server assigns a permanent constraint name at the time that you create the table.
To create, modify, or delete foreign-key constraints for the current table, select the Foreign option on the CONSTRAINTS menu. The FOREIGN KEY menu appears, as Figure 77 shows.
FOREIGN KEY mytab: Add Modify Drop Screen Exit
Add a constraint name or referencing/referenced column pair.
------Page 1 of 1 -------mydata@mydbserv------ Press CTRL-W for Help --------
Constraint Referencing Column Referenced Table Referenced Column CD
unassigned0 column1 table2 column1 Y
column2 column2
column3 column3
Use the menu options as follows:
ADD ENABLE CASCADING DELETES mytab3: No Yes
No, I do not want cascading deletes.
-------- Page 1 of 1 --------mydata@mydbserv------ Press CTRL-W for Help -----
Constraint Referencing Column Referenced Table Referenced Column CD
cons1 col1 yourtab col6 N
Select Yes to enable cascading deletes. When you delete a referenced (parent) record, you also delete all corresponding referencing (child) records. (Option Yes is equivalent to the ON DELETE CASCADE option of the REFERENCES clause in the CREATE TABLE statement.)
Select No to prevent cascading deletes. A referenced (parent) column cannot be deleted if referencing (child) records exist.
For a detailed description of referential integrity and cascading deletes, see the CREATE TABLE statement in the IBM Informix: Guide to SQL Syntax.
When you complete the Cascading Deletes entry, the cursor returns to the Constraint field. Enter another constraint or press the Interrupt key to return to the top line of the FOREIGN KEY menu.
Change the entry for the field and press RETURN to modify it, or press the Interrupt key if you do not want to modify a foreign constraint.
If the current (highlighted) field is Constraint, then the entire constraint is deleted. If any other field is highlighted, then only that referenced and referencing pair is deleted.
The default is Yes. Press RETURN to delete the highlighted constraint. Move the cursor to highlight No if you do not want to delete that constraint. You return to the FOREIGN KEY menu.
The CHECK CONSTRAINTS menu lets you add, modify, or delete a check constraint for the current table. Select the Check option on the CONSTRAINTS menu to access the CHECK CONSTRAINTS menu, as Figure 79 shows.
CHECK CONSTRAINTS mytab: Add Modify Drop Screen Exit
Add a check constraint.
-----------------mydata@mydbserv------------- Press CTRL-W for Help ---------
Constraint Name Value
cons2 (column1 > (c ...
cons3 column2 < col ...
cons4 column3 > 100
The CHECK CONSTRAINTS menu displays any previously added check constraints. The first 36 characters of the check value appear on the CHECK CONSTRAINTS menu. Use the CHECK CONSTRAINTS menu options as follows:
The default is Yes. Press RETURN to delete the highlighted constraint. Move the cursor to highlight No and then press RETURN if you do not want to delete that constraint. You return to the CHECK CONSTRAINTS menu.
ADD CHECK VALUE cons99: New Modify Use-editor Exit
Enter a new check value using the SQL editor.
----------------mydata@mydbserv------------- Press CTRL-W for Help --------
The ADD CHECK VALUE menu has the following options.
If you break from the ADD CHECK VALUE menu or exit without defining the check value, you return to the CHECK CONSTRAINTS menu. If you defined the check value, you remain in add mode, a new line is inserted, the Constraint Name is the current field, and the ADD CONSTRAINT NAME prompt appears.
The UNIQUE CONSTRAINTS menu lets you add, modify, or delete a unique constraint for the current table. To access the UNIQUE CONSTRAINTS menu, select the Unique option on the CONSTRAINTS menu, as Figure 81 shows.
UNIQUE CONSTRAINTS mytab: Add Modify Drop Screen Exit
Add a unique constraint.
------------------mydata@mydbserv------------ Press CTRL-W for Help ---------
Constraint Name Column Name
cons2 column1
column2
column3
cons3 column4
Use the UNIQUE CONSTRAINTS menu options as follows:
If you delete a constraint name, all column names associated with that constraint name are also deleted.
When you enter a unique constraint, DB–Access validates your entry by verifying the following information:
Use the DEFAULTS menu to define default values for columns in a table, as Figure 82 shows. To access the DEFAULTS menu, select the Defaults option on the CONSTRAINTS menu.
DEFAULTS mytab: Add Modify Drop Screen Exit
Add a column default.
-------Page 1 of 1 --------mydata@mydbserv----- Press CTRL-W for Help -------
Column Name Type Value
column1 User
column3 Null
column5 Today
column6 Current (Fraction to Fraction (5))
column7 Literal
column8 Literal 1200
The DEFAULTS menu has the following options.
You can see the first 28 characters of the value.
The Schema Editor inserts a new line at the top of the list and makes the Column Name the current field.
ADD DEFAULT TYPE mytab: Literal User Current Null Today Db-server-name Site-name
Assign a literal value using either the SQL editor or a system editor.
---------------mydata@mydbserv---------------- Press CTRL-W for Help ---------
The ADD DEFAULT TYPE menu has the following options that let you assign default values to the column.
The ADD DEFAULT VALUE menu lets you add or modify the default value for a column in the current table with either the SQL editor or a system editor, as Figure 84 shows.
ADD DEFAULT VALUE column7: New Modify Use-editor Exit
Enter a new default value using the SQL editor.
-----------------mydata@mydbserv------------- Press CTRL-W for Help ----------
The ADD DEFAULT VALUE menu displays the following options.
When you enter a default value, DB–Access validates your entry. The database server validates the literal value and checks the following information: