I would like to add key columns to my IMPORT_EMPLOYEE and IMPORT_PURCHASE tables so I can automate
Question:
I would like to add key columns to my IMPORT_EMPLOYEE and IMPORT_PURCHASE tables so I can automate primary and foreign keys column values. The assignment is as following:
IMPORT_EMPLOYEE table is
MPORT_PURCHASE table is
1. Add the columns PRIMARYID, EMPLOYEEID, ADDRESSID, SKILLID, SKILLTYPEID, DEPARTMENTID to IMPORT_EMPLOYEE. Make each column a NUMBER with 10 digits.
2. Add the columns PRIMARYID, CUSTOMERID, ADDRESSID, PURCHASEID, PRODUCTID to IMPORT_PURCHASE. Make each column a NUMBER with 10 digits.
3. Use the following UPDATE example on each import table to number each row
UPDATE import_table SET PrimaryID = ROWNUM;
4. Use the following UPDATE example on IMPORT_EMPLOYEE to assign values to update the EmployeeID, DepartmentID, SkillTypeID
field_ID | Identifying_attribute |
EmployeeID | EmployeeName |
DepartmentID | DepartmentName |
SkillTypeID | SkillName |
UPDATE IMPORT_EMPLOYEE
SET field_ID =
(
SELECT MIN(PrimaryID) FROM IMPORT_EMPLOYEE IT2
WHERE IT2.identifying_attribute =
IMPORT_EMPLOYEE.identifying_attribute
GROUP BY identifying_attribute
);
5. Use the following UPDATE example to assign values to update the CustomerID and ProductID
field_ID | identifying_attribute |
CustomerID | CustomerName |
ProductID | ProductName |
UPDATE IMPORT_PURCHASE
SET field_ID =
(
SELECT MIN(PrimaryID) FROM IMPORT_PURCHASE IT2
WHERE IT2.identifying_attribute =
IMPORT_PURCHASE.identifying_attribute
GROUP BY identifying_attribute
);
6. Use the following UPDATE example to update SkillID, PurchaseID, AddressID in the IMPORT_EMPLOYEE and IMPORT_PURCHASE tables
UPDATE import_table
SET field_ID = PrimaryID;
7. Use the following UPDATE example to avoid conflicting AddressIDs during imports
UPDATE IMPORT_PURCHASE
SET AddressID = PrimaryID + 9999;
8. Run COMMIT; so all connections can see your updated data
9. Confirm all Key columns in both import tables have values.
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill