In this example, you use SQL Developer to add a table constraint to the purchase_orders
table that you created in "Example: Creating a Table". To enforce the rule that the po_date_received
value must be either the same day as, or later than, the value of po_date
, you add a check constraint.
Note:
You can also add constraints during table creation, as shown in "Example: Creating a Table". In that example, you added a primary key constraint.
-
Navigate to the PURCHASE_ORDERS
table in the HR schema, following the instructions in "Viewing Tables".
-
Right-click the PURCHASE_ORDERS
table and select Edit.
The Edit Table dialog box appears.
-
Under the Search box, click Constraints.
-
To the right of the Constraints section, click the green plus sign icon and choose New Check Constraint.
In the Constraints section, a new row appears at the bottom of the list of constraints.
-
In the Name field for the new constraint, enter PO_CHECK_RCVD_DATE
.
-
Leave the check mark in the Enabled column and leave Not Deferrable.
-
In the Check Condition section, enter the following condition for this constraint:
PO_DATE_RECEIVED >= PO_DATE
This expression indicates that PO_DATE_RECEIVED
must be greater than or equal to PO_DATE
. For date columns, this is equivalent to stating that PO_DATE_RECEIVED
must be on the same day as, or later than, PO_DATE
.
-
Click OK.
-
On the PURCHASE_ORDERS tab in the object pane, click the Constraints subtab to view the current constraints in the table.