Pages

Saturday, May 22, 2010

Step 6 – Apex Developer Day - Adding a Constraint

You now have the employee data that is referenced by the APEX_TASKS.ASSIGNED_TO column but need to identify a foreign key between the tables APEX_ATASKS and APEX_EMPLOYEES. The foreign key ensures that each ASSIGNED_TO column references a valid Employee. It also ensures that an Employee cannot be deleted who has tasks assigned. Perform the following steps:

1.

Select the down arrow next to Object Browser > Browse and then select Tables.

clip_image002

2.

Select the APEX_TASKS table and click the Constraints tab.

clip_image004

3.

Click Create.

clip_image006

4.

Select Foreign Key for the Constraint Type. Select Cascade Delete in constraint type, ASSIGNED_TO for the Foreign Key Column, select OBE_EMPLOYEES for the Reference Table Name and select EMPLOYEE_ID from the Reference Table Column List. Then click Next .

clip_image008

5.

Click Finish.

clip_image010

clip_image012

6.

The constraint was created successfully. You want to also create a check constraint on the PROJECT_PRIORITY column so that the data is validated when the data is inserted or updated. Select APEX_PROJECT_LOOKUP.

clip_image014

7.

Click the Create section tab.

8.

Select PROJECT_PRIORITY for the Constraint of Column field and enter in ('1','2','3') for the Constraint Expression. Ensure that Check Constraint Type is selected. Then click Next.

clip_image016

9.

Click Finish.

clip_image018

10.

The constraint was created successfully. Click the Home breadcrumb.

clip_image020

No comments:

Post a Comment