DB Develop 2 Oracle 12c, DB2, MYSQL, SQL Anywhere 16

472 views
386 views

Published on

Published in: Software, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
472
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

DB Develop 2 Oracle 12c, DB2, MYSQL, SQL Anywhere 16

  1. 1. 0 Database Development2 Oracle 12c,DB2, MySQL & SQL Anywhere By Sunny U Okoro
  2. 2. 1 Contents Database Systems.........................................................................................................................................7 Applications...................................................................................................................................................9 ERD..............................................................................................................................................................14 Oracle 12C R1..............................................................................................................................................17 TableSpace and User Accounts...............................................................................................................19 Tables......................................................................................................................................................22 Index........................................................................................................................................................36 Triggers....................................................................................................................................................38 Database Altration..................................................................................................................................79 DBA Database Dictionary......................................................................................................................105 Database Physical Model..................................................................................................................106 Database Directory ...........................................................................................................................107 Database Population.............................................................................................................................152 Modifying the Table Column.................................................................................................................166 Database Verifcation- Regular Tables...................................................................................................178 Database Verifcation- Audit Tables ......................................................................................................184 Data Population and Mainpulation.......................................................................................................192 User Account Creations and Privileges ................................................................................................211 DBA Works ............................................................................................................................................286 MYSQL 5.6.................................................................................................................................................294 Database Creation.................................................................................................................................295 Tables....................................................................................................................................................297 Indexes..................................................................................................................................................309 Triggers..................................................................................................................................................311 Database Altration................................................................................................................................316 Data Population ....................................................................................................................................320 Database Dictionary..............................................................................................................................328 Database Physical Diagram..............................................................................................................329 Database Dictinoary..........................................................................................................................330 Data Verification Regular Tables...........................................................................................................477 Data Verification Audit Tables ..............................................................................................................481
  3. 3. 2 Data Mainpulation................................................................................................................................491 Revised Database Dictinoary ................................................................................................................563 Revised Database Diagram ...................................................................................................................565 DB2 10.......................................................................................................................................................567 Database Creation.................................................................................................................................569 Database Schema and Objecs Creations...............................................................................................579 Triggers..................................................................................................................................................594 Index......................................................................................................................................................601 Database Alteration..............................................................................................................................602 DBA Database Dictionary......................................................................................................................621 Database Physical Model..................................................................................................................623 Database Dictionary..........................................................................................................................624 Database Population.............................................................................................................................674 Database Verification-Regular Tables...................................................................................................685 Database Verification-Audit Tables ......................................................................................................691 Data Mainpulation................................................................................................................................697 Oracle PLSQL-DB2 .................................................................................................................................738 Revised Database Directinoary.............................................................................................................753 Revised Physical Database Diagram .....................................................................................................760 Sybase SQLAnywhere 16...........................................................................................................................762 Database Creation.....................................................................................................................................763 Tables....................................................................................................................................................770 Index......................................................................................................................................................778 Triggers..................................................................................................................................................779 Database Population.............................................................................................................................790 Database Altration....................................................................................................................................800 DBA Database Dictionary..........................................................................................................................802 Physical Database Diagram...................................................................................................................803 Database Dictinoary..............................................................................................................................804 Data Verification-Regular Tables ..........................................................................................................859 User Accounts Creation ........................................................................................................................871 Data Mainpulation................................................................................................................................877 Table Population and Data Mainpulation...........................................................................................887
  4. 4. 3 Materialized View .................................................................................................................................914 Revised Physical Database Dictinoary.......................................................................................................944 Revised Database Physical Diagram .....................................................................................................945 Remote Servers.....................................................................................................................................947
  5. 5. 4
  6. 6. 5
  7. 7. 6
  8. 8. 7 Database Systems Oracle 12c DB2 MySQL
  9. 9. 8 Sybase SQL Anywhere16
  10. 10. 9 Applications Microsoft Visio Microsoft Visual Studios 2010
  11. 11. 10 Sybase Central Quest Toad Data Point
  12. 12. 11 Oracle SQL Developer Oracle JDeveloper
  13. 13. 12 IBM DataStudio MySQL Workbench Quest TOAD forMYSQL
  14. 14. 13 Oracle SQL Developer Data Modeler
  15. 15. 14 ERD Store PK Store_ID PK,FK1 Employee_ID PK,FK2 Store_State_ID PK,FK1 Store_ManagerID Store_Name Store_Type Store_Address Store_City Store_Phone Store_Status Management PK Manager_ID PK,FK1 Employee_ID Hire_Date Hire_EndDate StateCodes PK State_ID PK,FK1 Country_Code State_Name State_Abbrv State_TaxRate CountryCode PK Country_Code Country_Name Country_Abbrv Employee PK Employee_ID PK,FK1 State_ID First_Name Middle_Name Last_Name Adress City Phone Gender HRRecords PK HR_ID PK,FK1,FK2 Employee_ID PK,FK2 Store_ID PK,FK3 Role_ID DOB SSN Hire_Date End_Date Pay_Rate Education Ethnicity Race Customer PK Customer_ID PK,FK1 State_ID First_Name Middle_Name Last_Name Address City Phone DOB Gender Education Job_Type Income_Level HRRoles PK Role_ID Role_Title Role_Status Product PK Product_ID PK,FK1 Product_CategoryID Product_Name Product_Color Product_Size Poduct_Weighit Product_Description ProductCategory PK Product_CategoryID Category_Name Category_Description Receipt PK Receipt_ID PK,FK1 State_ID PK,FK1,FK3 Employee_ID PK,FK2 Customer_ID PK,FK3 Store_ID PK,FK4 Receipt_StateCode PK,FK5 Product_ID Receipt_Amount Receipt_Tax Receipt_Date Receipt_FinalAmt QTY FK6 Transaction_ID Transaction PK,FK1 Payment_ID PK Transaction_ID Transaction_Date Transaction_Status Transaction_Amount Transaction_Tax Transaction_FinalAmt Shipment PK Shippingg_ID PK,FK1 Shipper_ID PK,FK2 Receipt_ID Ship_Date Ship_EndDate Receive_Date Name Address City FK2 State_ID Shippment_Amount Shiippment_Type FK2 Product_ID ShippingCo PK Shipper_ID Shipper_Name Status Created_Date PaymentCop PK Payment_ID Payment_Cop_Name Payment_Type Payment_Created_Date Payment_Status Howard Retails Conceptual Diagram
  16. 16. 15
  17. 17. 16 Customer PK Customer_ID PK,FK1 Country_Code PK,FK1 State_ID First_Name Middle_Name Last_Name Address City Phone DOB Employee PK Employee_ID PK,FK1 Country_Code PK,FK1 State_ID First_Name Middle_Name Last_Name Address City Phone Statecodes PK State_ID PK,FK1 Country_Code State_Name State_Abbrv State_TaxRate CountryCode PK Country_Code Country_Name Country_Abbrv HRRecords PK,FK4 Employee_ID PK HR_ID PK,FK2 Role_ID PK,FK3,FK4 Store_ID PK,FK4 Manager_ID DOB Social_SecurityNum Hire_Date End_Date PayRate Employement_Status HRROLES PK Role_iD Role_Title Role_Status Store PK Store_ID Store_StateID Store_Name Store_Type Store_Address Store_City Store_City Store_Phone Store_Status Management PK Manager_ID PK,FK1 Store_ID PK,FK2 Employee_ID Hire_Date Hire_Enddate Receipt PK Receipt_ID PK,FK1 Product_ID PK,FK2 Employee_ID PK,FK3 Customer_ID PK,FK4 Store_ID Receipt_Amount Receipt_Tax QTY Receipt_FinalAmt Receipt_Date Product PK Product_ID PK,FK1 Product_CategoryID Product_Name Product_Color Product_Size Product_Weight Product_Description ProductCategory PK Product_CategoryID Category_Name Category_Description ShippingCo PK Shipper_ID Shipper_Name Status Created_Date Shipment PK Ship_Date PK,FK1 Receipt_ID PK,FK2 Shipper_ID PK,FK3 Store_ID PK,FK4 Employee_ID PK,FK5 State_ID Shipping_ID Ship_EndDate Receive_Date Name Address City Shipping_Amount Shipping_Type Ship_QTY PaymentCop PK Payment_ID PK,FK1 Receipt_ID PK,FK2 Store_ID Payment_CopName Payment_Type Payment_CreatedDate Payment_Status PaymentCard_Number Payment_ExpDate Authorized_Amount Howard Retail Logical Database Diagram
  18. 18. 17 Oracle 12C R1
  19. 19. 18
  20. 20. 19 Note This development part for oracle has not been completed due to database failure but will be updated later in future relases. TableSpace and User Accounts SQL> show user; USER is "SYSTEM" SQL> create tablespace HowardRetail 2 datafile'C:Oracle12coradataUwaRetail' size 1G Online; Tablespace created. SQL> create temporary tablespace HowardRetail_Temp 2 tempfile 'C:Oracle12coradataUwaRetail_Temp' SIZE 80M autoextend on; Tablespace created. SQL> SQL> create user HowardDBA 2 Identified by howard 3 default tablespace HowardRetail; User created. SQL> SQL> Alter user HowardDBA 2 temporary tablespace HowardRetail_Temp; User altered. SQL> SQL> grant create session to HowardDBA; Grant succeeded. SQL> Grant resource to HowardDBA; Grant succeeded.
  21. 21. 20 Applications User Account Creations Oracle SQLDevelopern User Account Creation Oracle JDeveloper User Account Creation
  22. 22. 21 Microsoft Visual Studio User Account Creation
  23. 23. 22 Tables SQL> Alter table countrycode 2 modify Country_Name constraint country_coname_nn not null; Table altered. SQL> Alter table countrycode 2 modify Country_Abbrv constraint country_coabbrv_nn not null; Table altered. SQL> SQL> create table CountryCodesAudit 2 (Country_Code Integer, 3 Country_Name Varchar2(60), 4 Country_Abbrv Varchar2(12), 5 Audit_Date timestamp, 6 Audit_User varchar2(50), 7 old_countrycode integer, 8 old_countryname Varchar2(60), 9 old_countryabbrv Varchar2(12), 10 Audit_ID integer GENERATED ALWAYS AS IDENTITY 11 (START WITH 110 INCREMENT BY 1), 12 Action_Type char(20) 13 ); Table created. SQL> SQL> SQL> Create table statecodes 2 (State_ID integer GENERATED ALWAYS AS IDENTITY 3 (START WITH 220 INCREMENT BY 15) , 4 Country_Code integer, 5 State_Name varchar2(45) ,
  24. 24. 23 6 State_Abbrv varchar2(10) , 7 State_TaxRate integer , 8 constraint statecodes_statecode_pk primary key(State_ID, Country_Code), 9 constraint statecodes_statecode_uk unique (State_ID), 10 constraint Statecode_countrycode_fk foreign key (Country_Code) references 11 CountryCode(Country_Code) 12 ); Table created. SQL> Alter table statecodes 2 modify State_Name constraint statecode_statename_nn not null 3 modify State_Abbrv constraint statecode_stateabrv_nn not null 4 modify State_TaxRate constraint statecode_statetxrt_nn not null; Table altered. SQL> Create table StateCodesAudit 2 (State_ID integer, 3 Country_Code integer, 4 State_Name Varchar2(45), 5 State_Abbrv Varchar2(10), 6 State_TaxRate integer, 7 Audit_Date timestamp, 8 Audit_User varchar2(50), 9 Audit_ID integer GENERATED ALWAYS AS IDENTITY 10 (START WITH 200 INCREMENT BY 1), 11 Action_Type char(20), 12 Old_State_ID integer, 13 Old_Country_Code integer, 14 Old_State_Name Varchar2(45), 15 Old_State_Abbrv Varchar2(10), 16 Old_State_TaxRate integer ); Table created. SQL> SQL> SQL> SQL> create table Employee 2 (Employee_ID integer GENERATED ALWAYS AS IDENTITY 3 (START WITH 0443 INCREMENT BY 25) , 4 First_Name varchar2(55) , 5 Middle_Name varchar2(55), 6 Last_Name varchar2(55) , 7 Address varchar2(55) , 8 City varchar2(45) , 9 State_ID Integer , 10 Phone varchar2(45) , 11 constraint employee_empid_pk primary key(Employee_ID,State_ID), 12 constraint employee_empid_uk unique (Employee_ID), 13 constraint employee_stateid_fk foreign key(state_id) references statecodes(state_id)
  25. 25. 24 14 ); Table created. SQL> show user USER is "HOWARDDBA" SQL> SQL> SQL> SQL> SQL> SQL> Alter table Employee 2 modify First_Name constraint employee_firstname_nn not null 3 modify Last_Name constraint employee_lastname_nn not null 4 modify Address constraint employee_address_nn not null 5 modify city constraint employee_city_nn not null 6 modify phone constraint employee_phone_nn not null; Table altered. SQL> SQL> create table EmployeeAudit 2 (Employee_ID integer, 3 First_Name varchar2(55), 4 Middle_Name varchar2(55), 5 Last_Name Varchar2(55), 6 Address varchar2(55), 7 City Varchar2(45), 8 State_ID Integer, 9 Phone Varchar2(45), 10 Audit_Date timestamp, 11 Audit_User varchar2(50), 12 Audit_ID integer GENERATED ALWAYS AS IDENTITY 13 (START WITH 300 INCREMENT BY 1) , 14 Action_Type char(20), 15 Old_Employee_ID integer, 16 Old_First_Name varchar2(55), 17 Old_Middle_Name varchar2(55), 18 Old_Last_Name Varchar2(55), 19 Old_Address varchar2(55), 20 Old_City Varchar2(45), 21 Old_State_ID Integer, 22 Old_Phone Varchar2(45) 23 ); Table created. SQL> create table HRRoles 2 (Role_ID integer GENERATED ALWAYS AS IDENTITY 3 (START WITH 0421 INCREMENT BY 25) , 4 Role_Title varchar2(45), 5 Role_status varchar2(45), 6 constraint HRRoles_roleid_pk primary key(Role_ID) 7 );
  26. 26. 25 Table created. SQL> Alter table HRRoles 2 modify Role_Title constraint Hrroles_RoleTitle_nn not null 3 modify Role_status constraint Hrroles_Rolestatus_nn not null; Table altered. SQL> SQL> create table HRRolesAudit 2 (Role_ID integer, 3 Role_Title varchar2(45), 4 Role_status varchar2(45), 5 Old_RoleID integer, 6 Old_RoleTitle varchar2(45), 7 Old_Role_status varchar2(45), 8 Audit_Date timestamp, 9 Audit_User varchar2(50), 10 Audit_ID integer GENERATED ALWAYS AS IDENTITY 11 (START WITH 330 INCREMENT BY 1) , 12 Action_Type char(20) 13 ); Table created. SQL> SQL> Create table HRRecords 2 (Employee_ID Integer , 3 HR_ID Integer GENERATED ALWAYS AS IDENTITY (START WITH 0323 INCREMENT BY 20) , 4 Role_ID Integer , 5 Store_ID integer , 6 DOB Date not null, 7 Social_SecurityNum Integer , 8 Hire_Date Date , 9 End_Date Date, 10 PayRate numeric(15,2) , 11 Employement_Status varchar2(45), 12 constraint HrRecord_hrid_pk primary key(Employee_ID,HR_ID,Role_ID,Store_ID), 13 constraint HrRecord_hri_uk unique (HR_ID), 14 constraint HrRecord_empid_fk foreign key(Employee_ID) references Employee(Employee_ID) , 15 constraint HrRecord_roleid_fk foreign key(Role_ID) references HRRoles(Role_ID) 16 ); Table created. SQL> SQL> SQL> Create table HRRecordsAudit 2 (Employee_ID Integer, 3 HR_ID Integer, 4 Role_ID Integer, 5 Store_ID integer,
  27. 27. 26 6 DOB Date, 7 Social_SecurityNum Integer, 8 Hire_Date Date, 9 End_Date Date, 10 PayRate numeric(15,2), 11 Employement_Status varchar2(45), 12 Old_EmployeeID Integer, 13 Old_HRID Integer, 14 Old_RoleID Integer, 15 Old_StoreID integer, 16 Old_DOB Date, 17 Old_SocialSecurityNum Integer, 18 Old_HireDate Date, 19 Old_EndDate Date, 20 Old_PayRate numeric(15,2), 21 Old_EmployementStatus varchar2(45), 22 Audit_Date timestamp, 23 Audit_User varchar2(50), 24 Audit_ID integer GENERATED ALWAYS AS IDENTITY 25 (START WITH 400 INCREMENT BY 1) , 26 Action_Type char(20) 27 ); Table created. SQL> create table Management 2 (Manager_ID integer GENERATED ALWAYS AS IDENTITY 3 (START WITH 0123 INCREMENT BY 21) , 4 Employee_ID integer , 5 Hire_Date Date , 6 Hire_EndDate Date, 7 constraint Management_Magerid_pk primary key(Manager_ID,Employee_ID), 8 constraint Management_Magerid_uk unique(Manager_ID), 9 constraint Management_empid_fk foreign key(Employee_ID) references Employee(Employee_ID) 10 ); Table created. SQL> SQL> Alter table Management 2 modify Hire_Date constraint HireDate_nn not null; Table altered. SQL> SQL> create table ManagementAudit 2 (Manager_ID integer, 3 Employee_ID integer, 4 Hire_Date Date, 5 Hire_EndDate Date, 6 Old_ManagerID integer, 7 Old_EmployeeID integer, 8 Old_HireDate Date,
  28. 28. 27 9 Old_HireEndDate Date, 10 Audit_Date timestamp, 11 Audit_User varchar2(50), 12 Audit_ID integer GENERATED ALWAYS AS IDENTITY 13 (START WITH 500 INCREMENT BY 1) , 14 Action_Type char(20) 15 ); Table created. SQL> SQL> SQL> create table store 2 (Store_ID Integer GENERATED ALWAYS AS IDENTITY 3 (START WITH 025 INCREMENT BY 22) , 4 Store_StateID Integer, 5 Store_ManagerID Integer , 6 Store_Name varchar2(65) , 7 Store_Type varchar2(34) , 8 Store_Address varchar2(65) , 9 Store_City varchar2(45) , 10 Store_Phone varchar2(45), 11 Store_Status varchar2(30) , 12 constraint store_storeid_pk primary key(Store_ID,Store_StateID,Store_ManagerID), 13 constraint store_storeiid_uk unique(Store_ID), 14 constraint store_stateid_fk foreign key(Store_StateID) references statecodes 15 (State_ID), 16 constraint store_storeMagerID_FK Foreign key (Store_ManagerID) references Management(Manager_ID) 17 ); Table created. SQL> SQL> Alter table HRRecords 2 add constraint HrRecord_storeid_fk foreign key(Store_ID) references store(store_id); Table altered. SQL> SQL> Alter table store 2 modify Store_Name constraint store_storename_nn not null 3 modify Store_Type constraint store_storetype_nn not null 4 modify store_address constraint store_storeadd_nn not null 5 modify store_city constraint store_storecity_nn not null 6 modify store_phone constraint store_storephone_nn not null 7 modify store_status constraint store_storestatus_nn not null; Table altered. SQL> SQL> create table storeAudit
  29. 29. 28 2 (Store_ID Integer, 3 Store_StateID Integer, 4 Store_ManagerID Integer, 5 Store_Name Varchar2(65), 6 Store_Type Varchar2(34), 7 Store_Address Varchar2(65), 8 Store_City Varchar2(45), 9 Store_Phone Varchar2(45), 10 Store_Status Varchar2(30), 11 Old_StoreID Integer, 12 Old_StorStateID Integer, 13 Old_StorManagerID Integer, 14 Old_StorName Varchar2(65), 15 Old_StorType Varchar2(34), 16 Old_StorAddress Varchar2(65), 17 Old_StorCity Varchar2(45), 18 old_StorPhone Varchar2(45), 19 old_StorStatus Varchar2(30), 20 Audit_Date timestamp, 21 Audit_User varchar2(50), 22 Audit_ID integer GENERATED ALWAYS AS IDENTITY 23 (START WITH 600 INCREMENT BY 1) , 24 Action_Type char(20) 25 ); Table created. SQL> SQL> create table customer 2 (Customer_ID integer GENERATED ALWAYS AS IDENTITY 3 (START WITH 0643, INCREMENT BY 15) , 4 State_ID integer , 5 First_Name varchar2(50), 6 Middle_Name varchar2(50), 7 Last_Name varchar2(50), 8 Address varchar2(50), 9 City varchar2(45) , 10 Phone varchar2(45) , 11 DOB Date , 12 constraint customer_Customerid_pk primary key(customer_id,state_id), 13 constraint customer_customerid_uk unique (customer_id), 14 constraint customer_custstateid_fk foreign key(State_ID) references statecodes(State_ID) 15 ); (START WITH 0643, INCREMENT BY 15) , * ERROR at line 3: ORA-02000: missing ) keyword SQL> SQL> SQL> SQL>
  30. 30. 29 SQL> create table customer 2 (Customer_ID integer GENERATED ALWAYS AS IDENTITY 3 (START WITH 0643 INCREMENT BY 15) , 4 State_ID integer , 5 First_Name varchar2(50), 6 Middle_Name varchar2(50), 7 Last_Name varchar2(50), 8 Address varchar2(50), 9 City varchar2(45) , 10 Phone varchar2(45) , 11 DOB Date , 12 constraint customer_Customerid_pk primary key(customer_id,state_id), 13 constraint customer_customerid_uk unique (customer_id), 14 constraint customer_custstateid_fk foreign key(State_ID) references statecodes(State_ID) 15 ); Table created. SQL> SQL> Alter table customer 2 modify First_Name constraint customer_firstname_nn not null 3 modify last_Name constraint customer_lastname_nn not null 4 modify address constraint customer_address_nn not null 5 modify city constraint customer_city_nn not null 6 modify phone constraint customer_phone_nn not null 7 modify DOB constraint customer_dob_nn not null; Table altered. SQL> SQL> create table CustomerAudit 2 (Customer_ID integer, 3 State_ID integer, 4 First_Name Varchar2(50), 5 Middle_Name Varchar2(50), 6 Last_Name Varchar2(50), 7 Address Varchar2(50), 8 City Varchar2(45), 9 Phone Varchar2(45), 10 DOB Date, 11 Old_CustomerID integer, 12 Old_StateID integer, 13 Old_FirstName Varchar2(50), 14 Old_MiddleName Varchar2(50), 15 Old_LastName Varchar2(50), 16 Old_Address Varchar2(50), 17 Old_City Varchar2(45), 18 Old_Phone Varchar2(45), 19 Old_DOB Date, 20 Audit_Date timestamp, 21 Audit_User varchar2(50), 22 Audit_ID integer GENERATED ALWAYS AS IDENTITY 23 (START WITH 700 INCREMENT BY 1) , 24 Action_Type char(20)
  31. 31. 30 25 ); Table created. SQL> SQL> SQL> create table ProductCategory 2 (Product_CategoryID Integer GENERATED ALWAYS AS IDENTITY 3 (START WITH 0192 INCREMENT BY 19), 4 Category_Name varchar2(45) , 5 Category_Description clob, 6 constraint Prodcategory_prodcategory_pk primary key(Product_CategoryID) 7 ); Table created. SQL> SQL> Alter table ProductCategory 2 modify Category_Name constraint categoryName_nn not null; Table altered. SQL> SQL> SQL> create table ProductCategoryAudit 2 (Product_CategoryID Integer, 3 Category_Name Varchar2(45), 4 Category_Description clob, 5 Old_ProdCategoryID Integer, 6 Old_CategoryName Varchar2(45), 7 Old_CategoryDescription clob, 8 Audit_Date timestamp, 9 Audit_User varchar2(50), 10 Audit_ID integer GENERATED ALWAYS AS IDENTITY 11 (START WITH 800 INCREMENT BY 1), 12 Action_Type char(20) 13 ); Table created. SQL> SQL> create table product 2 (Product_ID Integer GENERATED ALWAYS AS IDENTITY 3 (START WITH 0292 INCREMENT BY 15), 4 Product_CategoryID Integer , 5 Product_Name varchar2(50), 6 Product_Color varchar2(35), 7 Product_Size varchar2(35), 8 Product_Weight varchar2(45), 9 Product_Description Clob, 10 constraint Product_Prodid_pk primary key(Product_ID,Product_CategoryID) 11 ,constraint product_prodid_uk unique (Product_ID),
  32. 32. 31 12 constraint product_prodcategoid_fk foreign key(Product_CategoryID) references 13 ProductCategory(Product_CategoryID) 14 ); Table created. SQL> Alter table Product 2 modify Product_Name constraint product_prodname_nn not null; Table altered. SQL> SQL> SQL> create table productAudit 2 (Product_ID Integer, 3 Product_CategoryID Integer, 4 Product_Name Varchar2(50), 5 Product_Color Varchar2(35), 6 Product_Size Varchar2(35), 7 Product_Weight Varchar2(45), 8 Product_Description Clob, 9 Old_ProductID Integer, 10 Old_ProdCategoryID Integer, 11 Old_ProdName Varchar2(50), 12 Old_ProdColor Varchar2(35), 13 Old_ProdSize Varchar2(35), 14 Old_ProdWeight Varchar2(45), 15 Old_ProdDescription Clob, 16 Audit_Date timestamp, 17 Audit_User varchar2(50), 18 Audit_ID integer GENERATED ALWAYS AS IDENTITY 19 (START WITH 900 INCREMENT BY 1) , 20 Action_Type char(20) 21 ); Table created. SQL> SQL> create table PaymentCop 2 (Payment_id integer GENERATED ALWAYS AS IDENTITY 3 (START WITH 0242 INCREMENT BY 14) , 4 Payment_CopName varchar2(50), 5 Payment_Type varchar2(45), 6 Payment_CreatedDare Date, 7 Payment_Status varchar2(25), 8 PaymentCard_Number integer, 9 Payment_ExpDate Date, 10 constraint PaymentCop_paymentid_pk primary key(Payment_id), 11 constraint Paymentcop_PaymentType_ck check (Payment_Type in('VISA','MasterCard', 'Discovery','American Express','NA', 12 'visa','mastercard','discovery','american express')) 13 ); Table created.
  33. 33. 32 SQL> SQL> SQL> Alter table PaymentCop 2 modify PaymentCard_Number constraint Paymentcop_Paycardnum_nn not null 3 modify Payment_CopName constraint Paymentcop_PayCopName_nn not null 4 modify Payment_Type constraint Paymentcop_PaycopType_nn not null; Table altered. SQL> SQL> create table PaymentCopAudit 2 (Payment_id integer, 3 Payment_CopName Varchar2(50), 4 Payment_Type Varchar2(45), 5 Payment_CreatedDare Date, 6 Payment_Status varchar2(25), 7 PaymentCard_Number integer, 8 Old_Payid integer, 9 Old_PayCopName Varchar2(50), 10 old_PayType Varchar2(45), 11 Old_PayCreatedDare Date, 12 Old_PayStatus varchar2(25), 13 Old_PayCard_Number integer, 14 Audit_Date timestamp, 15 Audit_User varchar2(50), 16 Audit_ID integer GENERATED ALWAYS AS IDENTITY 17 (START WITH 1000 INCREMENT BY 1) , 18 Action_Type char(20) 19 ); Table created. SQL> SQL> create table Receipt 2 (Receipt_ID Integer GENERATED ALWAYS AS IDENTITY 3 (START WITH 0232 INCREMENT BY 20), 4 State_ID integer , 5 Employee_ID integer , 6 Customer_ID integer , 7 Store_ID integer , 8 Receipt_StateCode Integer, 9 Product_ID Integer , 10 Receipt_Amount decimal (8,2), 11 Receipt_Tax decimal (8,2) , 12 QTY Integer , 13 Receipt_FinalAmt decimal (8,2), 14 Payment_ID integer , 15 constraint Receipt_Receipid_pk primary key(Receipt_ID,State_ID,Employee_ID,Customer_ID,Store_ID 16 ,Receipt_StateCode,Product_ID, Payment_ID), 17 constraint Receipt_Receiptid_uk unique (Receipt_ID), 18 constraint Receipt_customerid_fk foreign key(Customer_ID) references Customer(Customer_ID), 19 constraint Receipt_Employeeid_fk foreign key(Employee_ID) references Employee (Employee_ID),
  34. 34. 33 20 constraint Receipt_Stateid_fk foreign key(State_ID) references statecodes(state_id), 21 constraint Receipt_storeid_fk foreign key(Store_id) references store(Store_id), 22 constraint Receipt_Productid_fk foreign key(Product_ID) references Product (Product_ID), 23 constraint Receipt_paymentid_fk foreign key(Payment_ID) references PaymentCOP(Payment_ID) 24 ); Table created. SQL> SQL> Alter table Receipt 2 add Receipt_Date DATE; Table altered. SQL> Alter table Receipt 2 modify Receipt_Amount constraint receipt_ReceiptAmount_nn not null 3 modify Receipt_Tax constraint receipt_ReceiptTax_nn not null 4 modify QTY constraint receipt_qty_nn not null 5 modify Receipt_Date constraint Receipt_Date_nn not null 6 modify Receipt_FinalAmt constraint Receipt_FinalAmt_nn not null; Table altered. SQL> SQL> SQL> create table ReceiptAudit 2 (Receipt_ID Integer, 3 State_ID integer, 4 Employee_ID integer, 5 Customer_ID integer, 6 Store_ID integer, 7 Receipt_StateCode Integer, 8 Product_ID Integer, 9 Receipt_Amount numeric , 10 Receipt_Tax decimal (8,2), 11 QTY Integer, 12 Receipt_FinalAmt numeric, 13 old_ReceiptID Integer, 14 old_StateID integer, 15 old_EmployeeID integer, 16 Old_CustomerID integer, 17 old_StoreID integer, 18 Old_RecptStatecd integer, 19 Old_Prodid integer, 20 Old_RecptAmt numeric, 21 Old_Recepttax decimal(8,2), 22 Old_QTY Integer, 23 old_recptFinalAmt numeric, 24 Audit_Date timestamp, 25 Audit_User varchar2(50), 26 Audit_ID integer GENERATED ALWAYS AS IDENTITY 27 (START WITH 1200 INCREMENT BY 1) ,
  35. 35. 34 28 Action_Type char(20) 29 ); Table created. SQL> Alter table ReceiptAudit 2 add Receipt_Date DATE; Table altered. SQL> SQL> Alter table ReceiptAudit 2 add Old_ReceiptDate DATE; Table altered. SQL> SQL> SQL> create table shippingco 2 (shipper_id integer GENERATED ALWAYS AS IDENTITY 3 (START WITH 0242 INCREMENT BY 25), 4 Shipper_Name varchar2(50) , 5 status char(25) , 6 Create_date date, 7 constraint shippingco_shipperid_pk primary key(shipper_id) 8 ); Table created. SQL> SQL> Alter table shippingco 2 modify Shipper_Name constraint shipco_shippername_nn not null 3 modify status constraint shipco_status_nn not null; Table altered. SQL> SQL> SQL> SQL> create table shippingcoAudit 2 (shipper_id integer, 3 Shipper_Name Varchar2(50), 4 status char(25), 5 Create_date date, 6 Old_shipperid integer, 7 old_ShipperName Varchar2(50), 8 old_status char(25), 9 old_Create_date date, 10 Audit_Date timestamp, 11 Audit_User varchar2(50), 12 Audit_ID integer GENERATED ALWAYS AS IDENTITY 13 (START WITH 1300 INCREMENT BY 1), 14 Action_Type char(20) 15 );
  36. 36. 35 Table created. SQL> SQL> create table shipment 2 (shipping_id integer GENERATED ALWAYS AS IDENTITY 3 (START WITH 0235 INCREMENT BY 26), 4 shipper_id integer , 5 state_id integer , 6 Receipt_ID integer , 7 ship_date date, 8 ship_enddate date, 9 receive_date date, 10 Name varchar2(55), 11 Address varchar2(55), 12 City varchar2(55), 13 shipping_amount numeric, 14 shipping_type char(35), 15 constraint shipment_shipmentid_pk primary key(shipping_id,shipper_id,RECEIPT_ID ), 16 constraint shipment_shipermid_uk unique (shipping_id), 17 constraint shipment_shipperid_fk foreign key(shipper_id) references shippingco(shipper_id), 18 CONSTRAINT SHIPMENT_RECEIPTID_FK FOREIGN KEY(RECEIPT_ID) REFERENCES RECEIPT(RECEIPT_ID) 19 ); Table created. SQL> SQL> SQL> SQL> create table shippmentAudit 2 (shipping_id integer, 3 shipper_id integer, 4 state_id integer, 5 Receipt_ID integer, 6 ship_date date, 7 ship_enddate date, 8 receive_date date, 9 Name varchar2(55), 10 Address Varchar2(55), 11 City varchar2(55), 12 shipping_amount number, 13 shipping_type char(35), 14 old_shippingid integer, 15 old_shipperid integer, 16 old_stateid integer, 17 old_ReceiptID integer, 18 old_shipdate date, 19 old_shipenddate date, 20 old_receivedate date, 21 old_Name varchar2(55), 22 old_Address Varchar2(55), 23 old_City varchar2(55), 24 old_shippingamt number,
  37. 37. 36 25 old_shippingtype char(35), 26 Audit_Date timestamp, 27 Audit_User varchar2(50), 28 Audit_ID integer GENERATED ALWAYS AS IDENTITY 29 (START WITH 2000 INCREMENT BY 26), 30 Action_Type char(20) 31 ); Table created. Index SQL> SQL> create index Management_HireDate_indx on Management (Hire_Date); Index created. SQL> create index shippment_shippmentname_indx on shipment (Name); Index created. SQL> create index country_countryname_idx on countrycode (Country_Name); Index created. SQL> create index country_countryabbrv_indx on countrycode (Country_Abbrv) ; Index created. SQL> create index statecodes_statename_indx on statecodes (State_Name); Index created. SQL> create index statecodes_StateAbbrv_indx on statecodes (State_Abbrv); Index created. SQL> create index statecodes_TaxRate_indx on statecodes (State_TaxRate); Index created. SQL> create index Employee_FirstName_indx on Employee (First_Name); Index created. SQL> set echo off SQL> spool off
  38. 38. 37
  39. 39. 38 Triggers SQL> SQL> --This trigger will populate the audit date using the date from oracle date automatically-- SQL> SQL> SQL> create or replace trigger concodeAudit_auditdate_trgg 2 before insert on CountryCodesAudit 3 for each row 4 begin 5 select sysdate into :New.Audit_Date from dual; 6 end concodeAudit_auditdate_trgg; 7 / Trigger created. SQL> SQL> SQL> --This trigger will populate the CountryCodesAudit table automatically by selecting the user-- SQL> SQL> create or replace trigger concodeAudit_audituser_trgg 2 before insert on CountryCodesAudit 3 for each row 4 begin 5 select user into :New.Audit_User from dual; 6 end concodeAudit_audituser_trgg ; 7 / Trigger created. SQL> SQL> SQL> SQL> SQL> create or replace trigger CountryCodesAudit_del_trigg 2 after delete on countrycode 3 for each row 4 DECLARE 5 OCCD INTEGER; 6 OCCN Varchar2(60); 7 OCAB Varchar2(12); 8 ACT char(20); 9 begin 10 SELECT :OLD.Country_Code INTO OCCD FROM DUAL; 11 SELECT :OLD.Country_Name INTO OCCN FROM DUAL; 12 SELECT :OLD.Country_Abbrv INTO OCAB FROM DUAL; 13 SELECT 'Delete' INTO ACT FROM DUAL; 14 15 INSERT INTO CountryCodesAudit(old_countrycode, old_countryname,old_countryabbrv, Action_Type ) 16 SELECT OCCD, OCCN, OCAB, ACT FROM DUAL; 17 18 end CountryCodesAudit_del_trigg;
  40. 40. 39 19 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> SQL> create or replace trigger CountryCodesAudit_inst_trigg 2 after insert on countrycode 3 for each row 4 5 DECLARE 6 NCCD INTEGER; 7 NCCN Varchar2(60); 8 NCAB Varchar2(12); 9 ACT char(20); 10 11 begin 12 13 SELECT :NEW.Country_Code INTO NCCD FROM DUAL; 14 SELECT :NEW.Country_Name INTO NCCN FROM DUAL; 15 SELECT :NEW.Country_Abbrv INTO NCAB FROM DUAL; 16 SELECT 'Insert' INTO ACT FROM DUAL; 17 18 19 INSERT INTO CountryCodesAudit(Country_Code, Country_Name,Country_Abbrv, Action_Type ) 20 SELECT NCCD, NCCN, NCAB, ACT FROM DUAL; 21 22 23 end CountryCodesAudit_inst_trigg; 24 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> create or replace trigger CountryCodesAudit_upd_trigg 2 after update on countrycode 3 for each row 4 DECLARE 5 NCCD INTEGER; 6 NCCN Varchar2(60); 7 NCAB Varchar2(12); 8 OCCD INTEGER; 9 OCCN Varchar2(60); 10 OCAB Varchar2(12); 11 ACT char(20); 12 13 begin 14
  41. 41. 40 15 SELECT :NEW.Country_Code INTO NCCD FROM DUAL; 16 SELECT :NEW.Country_Name INTO NCCN FROM DUAL; 17 SELECT :NEW.Country_Abbrv INTO NCAB FROM DUAL; 18 SELECT :OLD.Country_Code INTO OCCD FROM DUAL; 19 SELECT :OLD.Country_Name INTO OCCN FROM DUAL; 20 SELECT :OLD.Country_Abbrv INTO OCAB FROM DUAL; 21 SELECT 'Update' INTO ACT FROM DUAL; 22 23 24 INSERT INTO CountryCodesAudit(Country_Code, Country_Name,Country_Abbrv,old_countrycode, old_countryname, 25 old_countryabbrv, Action_Type ) 26 SELECT NCCD, NCCN, NCAB,OCCD, OCCN, OCAB, ACT FROM DUAL; 27 28 29 end CountryCodesAudit_upd_trigg; 30 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> create or replace trigger statecodesAudit_auditdate_trgg 2 before insert on StateCodesAudit 3 for each row 4 begin 5 select sysdate into :New.Audit_Date from dual; 6 end statecodesAudit_auditdate_trgg; 7 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> create or replace trigger statecodesAudit_audituser_trgg 2 before insert on StateCodesAudit 3 for each row 4 begin 5 select user into :New.Audit_User from dual; 6 end statecodesAudit_audituser_trgg; 7 / Trigger created. SQL> SQL> SQL> SQL> SQL>
  42. 42. 41 SQL> CREATE OR REPLACE TRIGGER statecodesAdut_del_trigg 2 AFTER DELETE on STATECODES 3 FOR EACH ROW 4 DECLARE 5 OSTID INTEGER; 6 OCCD INTEGER; 7 OSTN Varchar2(45); 8 OSTAB Varchar2(10); 9 OSTRT Integer; 10 ACT char(20); 11 BEGIN 12 SELECT :OLD.State_ID INTO OSTID FROM DUAL; 13 SELECT :OLD.Country_Code INTO OCCD FROM DUAL; 14 SELECT :OLD.State_Name INTO OSTN FROM DUAL; 15 SELECT :OLD.State_Abbrv INTO OSTAB FROM DUAL; 16 SELECT :OLD.State_TaxRate INTO OSTRT FROM DUAL; 17 SELECT 'Delete' INTO ACT FROM DUAL; 18 19 INSERT INTO STATECODESAUDIT( Old_State_ID ,Old_Country_Code,Old_State_Name,Old_State_Abbrv,Old_State_TaxRate, 20 Action_Type) 21 SELECT OSTID, OCCD, OSTN,OSTAB,OSTRT,ACT FROM DUAL; 22 23 24 END statecodesAdut_del_trigg; 25 / Trigger created. SQL> SQL> SQL> CREATE OR REPLACE TRIGGER statecodesAdut_inst_trigg 2 AFTER INSERT on STATECODES 3 FOR EACH ROW 4 DECLARE 5 NSTID INTEGER; 6 NCCD INTEGER; 7 NSTN Varchar2(45); 8 NSTAB Varchar2(10); 9 NSTRT Integer; 10 ACT char(20); 11 BEGIN 12 SELECT :NEW.State_ID INTO NSTID FROM DUAL; 13 SELECT :NEW.Country_Code INTO NCCD FROM DUAL; 14 SELECT :NEW.State_Name INTO NSTN FROM DUAL; 15 SELECT :NEW.State_Abbrv INTO NSTAB FROM DUAL; 16 SELECT :NEW.State_TaxRate INTO NSTRT FROM DUAL; 17 SELECT 'INSERT' INTO ACT FROM DUAL; 18 19 INSERT INTO STATECODESAUDIT( State_ID ,Country_Code,State_Name,State_Abbrv,State_TaxRate, 20 Action_Type) 21 SELECT NSTID, NCCD, NSTN,NSTAB,NSTRT,ACT FROM DUAL; 22 23 24 25 END statecodesAdut_inst_trigg;
  43. 43. 42 26 / Trigger created. SQL> SQL> SQL> CREATE OR REPLACE TRIGGER statecodesAdut_upd_trigg 2 AFTER UPDATE on STATECODES 3 FOR EACH ROW 4 DECLARE 5 NSTID INTEGER; 6 NCCD INTEGER; 7 NSTN Varchar2(45); 8 NSTAB Varchar2(10); 9 NSTRT Integer; 10 OSTID INTEGER; 11 OCCD INTEGER; 12 OSTN Varchar2(45); 13 OSTAB Varchar2(10); 14 OSTRT Integer; 15 ACT char(20); 16 BEGIN 17 SELECT :NEW.State_ID INTO NSTID FROM DUAL; 18 SELECT :NEW.Country_Code INTO NCCD FROM DUAL; 19 SELECT :NEW.State_Name INTO NSTN FROM DUAL; 20 SELECT :NEW.State_Abbrv INTO NSTAB FROM DUAL; 21 SELECT :NEW.State_TaxRate INTO NSTRT FROM DUAL; 22 SELECT :OLD.State_ID INTO OSTID FROM DUAL; 23 SELECT :OLD.Country_Code INTO OCCD FROM DUAL; 24 SELECT :OLD.State_Name INTO OSTN FROM DUAL; 25 SELECT :OLD.State_Abbrv INTO OSTAB FROM DUAL; 26 SELECT :OLD.State_TaxRate INTO OSTRT FROM DUAL; 27 SELECT 'Update' INTO ACT FROM DUAL; 28 29 INSERT INTO STATECODESAUDIT( State_ID ,Country_Code,State_Name,State_Abbrv,State_TaxRate, 30 Old_State_ID ,Old_Country_Code,Old_State_Name,Old_State_Abbrv,Old_State_TaxRate, Action_Type) 31 SELECT NSTID, NCCD, NSTN,NSTAB,NSTRT,OSTID, OCCD, OSTN,OSTAB,OSTRT ,ACT FROM DUAL; 32 33 34 35 END statecodesAdut_upd_trigg; 36 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL>
  44. 44. 43 SQL> SQL> SQL> create or replace trigger EmployeeAudit_auditdate_trgg 2 before insert on EmployeeAudit 3 for each row 4 begin 5 select sysdate into :New.Audit_Date from dual; 6 end EmployeeAudit_auditdate_trgg; 7 / Trigger created. SQL> SQL> SQL> CREATE OR REPLACE TRIGGEr EmployeeAudit_audituser_trgg 2 BEFORE INSERT ON EMPLOYEEAUDIT 3 FOR EACH ROW 4 BEGIN 5 SELECT USER INTO :NEW.AUDIT_USER FROM DUAL; 6 END EMPLOYEEAUDIT_AUDITUSER_TRGG; 7 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER EmployeeAudit_del_trigg 2 AFTER DELETE ON EMPLOYEE 3 FOR EACH ROW 4 5 DECLARE 6 7 OEMP INTEGER; 8 OFN varchar2(55); 9 OMN varchar2(55) ; 10 OLN Varchar2(55); 11 OAD varchar2(55); 12 OCIT Varchar2(45); 13 OSTD Integer; 14 OPN Varchar2(45); 15 ACT char(20); 16 BEGIN 17 SELECT :OLD.Employee_ID INTO OEMP FROM DUAL; 18 SELECT :OLD.First_Name INTO OFN FROM DUAL; 19 SELECT :OLD.Middle_Name INTO OMN FROM DUAL; 20 SELECT :OLD.Last_Name INTO OLN FROM DUAL; 21 SELECT :OLD.Address INTO OAD FROM DUAL; 22 SELECT :OLD.City INTO OCIT FROM DUAL; 23 SELECT :OLD.State_ID INTO OSTD FROM DUAL; 24 SELECT :OLD.Phone INTO OPN FROM DUAL; 25 SELECT 'Delete' INTO ACT FROM DUAL; 26 27
  45. 45. 44 28 29 INSERT INTO EMPLOYEEAUDIT( Old_Employee_ID ,Old_First_Name,Old_Middle_Name,Old_Last_Name,Old_Address,Old_City, Old_State_ID, 30 Old_Phone , Action_Type) 31 SELECT OEMP,OFN, OMN, OLN ,OAD, OCIT ,OSTD ,OPN ,ACT FROM DUAL; 32 33 34 end EmployeeAudit_del_trigg; 35 / Trigger created. SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER EmployeeAudit_inst_trigg 2 AFTER INSERT ON EMPLOYEE 3 FOR EACH ROW 4 DECLARE 5 NEMP INTEGER; 6 NFN varchar2(55); 7 NMN varchar2(55) ; 8 NLN Varchar2(55); 9 NAD varchar2(55); 10 NCIT Varchar2(45); 11 NSTD Integer; 12 NPN Varchar2(45); 13 ACT char(20); 14 BEGIN 15 SELECT :NEW.Employee_ID INTO NEMP FROM DUAL; 16 SELECT :NEW.First_Name INTO NFN FROM DUAL; 17 SELECT :NEW.Middle_Name INTO NMN FROM DUAL; 18 SELECT :NEW.Last_Name INTO NLN FROM DUAL; 19 SELECT :NEW.Address INTO NAD FROM DUAL; 20 SELECT :NEW.City INTO NCIT FROM DUAL; 21 SELECT :NEW.State_ID INTO NSTD FROM DUAL; 22 SELECT :NEW.Phone INTO NPN FROM DUAL; 23 SELECT 'Insert' INTO ACT FROM DUAL; 24 25 INSERT INTO EMPLOYEEAUDIT( Employee_ID ,First_Name,Middle_Name,Last_Name,Address,City, State_ID, 26 Phone , Action_Type) 27 SELECT NEMP,NFN, NMN, NLN ,NAD, NCIT ,NSTD ,NPN ,ACT FROM DUAL; 28 29 30 end EmployeeAudit_inst_trigg; 31 / Trigger created. SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER EmployeeAudit_updt_trigg
  46. 46. 45 2 AFTER UPDATE ON EMPLOYEE 3 FOR EACH ROW 4 DECLARE 5 NEMP INTEGER; 6 NFN varchar2(55); 7 NMN varchar2(55) ; 8 NLN Varchar2(55); 9 NAD varchar2(55); 10 NCIT Varchar2(45); 11 NSTD Integer; 12 NPN Varchar2(45); 13 OEMP INTEGER; 14 OFN varchar2(55); 15 OMN varchar2(55) ; 16 OLN Varchar2(55); 17 OAD varchar2(55); 18 OCIT Varchar2(45); 19 OSTD Integer; 20 OPN Varchar2(45); 21 ACT char(20); 22 BEGIN 23 SELECT :NEW.Employee_ID INTO NEMP FROM DUAL; 24 SELECT :NEW.First_Name INTO NFN FROM DUAL; 25 SELECT :NEW.Middle_Name INTO NMN FROM DUAL; 26 SELECT :NEW.Last_Name INTO NLN FROM DUAL; 27 SELECT :NEW.Address INTO NAD FROM DUAL; 28 SELECT :NEW.City INTO NCIT FROM DUAL; 29 SELECT :NEW.State_ID INTO NSTD FROM DUAL; 30 SELECT :NEW.Phone INTO NPN FROM DUAL; 31 SELECT :OLD.Employee_ID INTO OEMP FROM DUAL; 32 SELECT :OLD.First_Name INTO OFN FROM DUAL; 33 SELECT :OLD.Middle_Name INTO OMN FROM DUAL; 34 SELECT :OLD.Last_Name INTO OLN FROM DUAL; 35 SELECT :OLD.Address INTO OAD FROM DUAL; 36 SELECT :OLD.City INTO OCIT FROM DUAL; 37 SELECT :OLD.State_ID INTO OSTD FROM DUAL; 38 SELECT :OLD.Phone INTO OPN FROM DUAL; 39 SELECT 'Update' INTO ACT FROM DUAL; 40 41 42 43 INSERT INTO EMPLOYEEAUDIT( Employee_ID ,First_Name,Middle_Name,Last_Name,Address,City, State_ID, 44 Phone , Old_Employee_ID ,Old_First_Name,Old_Middle_Name,Old_Last_Name,Old_Address,Old_City, Old_State_ID, 45 Old_Phone, Action_Type) 46 SELECT NEMP,NFN, NMN, NLN ,NAD, NCIT ,NSTD ,NPN ,OEMP,OFN, OMN, OLN ,OAD, OCIT ,OSTD ,OPN , ACT FROM DUAL; 47 48 end EmployeeAudit_updt_trigg; 49 / Trigger created. SQL> SQL>
  47. 47. 46 SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER HRRolesAudit_auditdate_trgg 2 BEFORE INSERT ON HRROLESAUDIT 3 FOR EACH ROW 4 BEGIN 5 SELECT SYSDATE INTO :NEW.AUDIT_DATE FROM DUAL; 6 END HRROLESAUDIT_AUDITDATE_TRGG; 7 / Trigger created. SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGEr HRRolesAudit_audituser_trgg 2 BEFORE INSERT ON HRROLESAUDIT 3 FOR EACH ROW 4 BEGIN 5 select user into :New.Audit_User from dual; 6 end HRRolesAudit_audituser_trgg; 7 / Trigger created. SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER HRRolesAudit_del_trigg 2 AFTER DELETE ON HRRoles 3 FOR EACH ROW 4 5 DECLARE 6 ORID INTEGER; 7 ORTL varchar2(45); 8 ORST varchar2(45) ; 9 ACT char(20); 10 BEGIN 11 SELECT :OLD.Role_ID INTO ORID FROM DUAL; 12 SELECT :OLD.Role_Title INTO ORTL FROM DUAL; 13 SELECT :OLD.Role_status INTO ORST FROM DUAL; 14 SELECT 'Delete' INTO ACT FROM DUAL; 15 16 17 INSERT INTO HRRolesAudit(Old_RoleID,Old_RoleTitle ,Old_Role_status 18 ,Action_Type) 19 SELECT ORID,ORTL, ORST , ACT FROM DUAL; 20
  48. 48. 47 21 END HRRolesAudit_del_trigg; 22 / Trigger created. SQL> SQL> SQL> CREATE OR REPLACE TRIGGER HRRolesAudit_inst_trigg 2 AFTER INSERT ON HRRoles 3 FOR EACH ROW 4 5 DECLARE 6 NRID INTEGER; 7 NRTL varchar2(45); 8 NRST varchar2(45) ; 9 ACT char(20); 10 BEGIN 11 SELECT :NEW.Role_ID INTO NRID FROM DUAL; 12 SELECT :NEW.Role_Title INTO NRTL FROM DUAL; 13 SELECT :NEW.Role_status INTO NRST FROM DUAL; 14 SELECT 'Insert' INTO ACT FROM DUAL; 15 16 17 INSERT INTO HRRolesAudit(Role_ID,Role_Title ,Role_status 18 ,Action_Type) 19 SELECT NRID,NRTL, NRST , ACT FROM DUAL; 20 21 END HRRolesAudit_inst_trigg; 22 / Trigger created. SQL> SQL> SQL> CREATE OR REPLACE TRIGGER HRRolesAudit_upd_trigg 2 AFTER UPDATE ON HRRoles 3 FOR EACH ROW 4 5 DECLARE 6 NRID INTEGER; 7 NRTL varchar2(45); 8 NRST varchar2(45) ; 9 ORID INTEGER; 10 ORTL varchar2(45); 11 ORST varchar2(45) ; 12 ACT char(20); 13 BEGIN 14 SELECT :NEW.Role_ID INTO NRID FROM DUAL; 15 SELECT :NEW.Role_Title INTO NRTL FROM DUAL; 16 SELECT :NEW.Role_status INTO NRST FROM DUAL; 17 SELECT :OLD.Role_ID INTO ORID FROM DUAL; 18 SELECT :OLD.Role_Title INTO ORTL FROM DUAL; 19 SELECT :OLD.Role_status INTO ORST FROM DUAL; 20 SELECT 'Update' INTO ACT FROM DUAL; 21 22
  49. 49. 48 23 INSERT INTO HRRolesAudit(Role_ID,Role_Title ,Role_status,Old_RoleID,Old_RoleTitle ,Old_Role_status 24 ,Action_Type) 25 SELECT NRID,NRTL, NRST ,ORID,ORTL, ORST, ACT FROM DUAL; 26 27 END HRRolesAudit_upd_trigg; 28 / Trigger created. SQL> SQL> SQL> CREATE OR REPLACE TRIGGER HRRecordsAudit_auditdate_trgg 2 BEFORE INSERT ON HRRECORDSAUDIT 3 FOR EACH ROW 4 BEGIN 5 SELECT SYSDATE INTO :NEW.AUDIT_DATE FROM DUAL; 6 end HRRecordsAudit_auditdate_trgg; 7 / Trigger created. SQL> SQL> SQL> CREATE OR REPLACE TRIGGER HRRecordsAudit_audituser_trgg 2 BEFORE INSERT ON HRRecordsAudit 3 FOR EACH ROW 4 BEGIN 5 SELECT USER INTO :NEW.AUDIT_USER FROM DUAL; 6 end HRRecordsAudit_audituser_trgg; 7 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER HRRecordsAudit_del_trigg 2 AFTER DELETE ON HRRecords 3 FOR EACH ROW 4 DECLARE 5 OEMP INTEGER; 6 OHRD INTEGER; 7 ORID INTEGER ; 8 OSTD INTEGER; 9 ODB DATE; 10 OSSN INTEGER; 11 OHD Date; 12 OEND Date; 13 OPR numeric(15,2); 14 OEMS varchar2(45); 15 ACT char(20);
  50. 50. 49 16 17 BEGIN 18 SELECT :OLD.Employee_ID INTO OEMP FROM DUAL; 19 SELECT :OLD.HR_ID INTO OHRD FROM DUAL; 20 SELECT :OLD.Role_ID INTO ORID FROM DUAL; 21 SELECT :OLD.Store_ID INTO OSTD FROM DUAL; 22 SELECT :OLD.DOB INTO ODB FROM DUAL; 23 SELECT :OLD.Social_SecurityNum INTO OSSN FROM DUAL; 24 SELECT :OLD.Hire_Date INTO OHD FROM DUAL; 25 SELECT :OLD.End_Date INTO OEND FROM DUAL; 26 SELECT :OLD.PayRate INTO OPR FROM DUAL; 27 SELECT :OLD.Employement_Status INTO OEMS FROM DUAL; 28 SELECT 'Delete' INTO ACT FROM DUAL; 29 30 INSERT INTO HRRecordsAudit(Old_EmployeeID,Old_HRID,Old_RoleID,Old_StoreID,Old_DOB , 31 Old_SocialSecurityNum,Old_HireDate, Old_EndDate,Old_PayRate,Old_EmployementStatus,Action_Type) 32 SELECT OEMP, OHRD, ORID, OSTD, ODB,OSSN,OHD, OEND, OPR,OEMS,ACT FROM DUAL; 33 end HRRecordsAudit_del_trigg; 34 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER HRRecordsAudit_inst_trigg 2 AFTER INSERT ON HRRecords 3 FOR EACH ROW 4 DECLARE 5 NEMP INTEGER; 6 NHRD INTEGER; 7 NRID INTEGER ; 8 NSTD INTEGER; 9 NDB DATE; 10 NSSN INTEGER; 11 NHD Date; 12 NEND Date; 13 NPR numeric(15,2); 14 NEMS varchar2(45); 15 ACT char(20); 16 17 BEGIN 18 SELECT :NEW.Employee_ID INTO NEMP FROM DUAL; 19 SELECT :NEW.HR_ID INTO NHRD FROM DUAL; 20 SELECT :NEW.Role_ID INTO NRID FROM DUAL; 21 SELECT :NEW.Store_ID INTO NSTD FROM DUAL; 22 SELECT :NEW.DOB INTO NDB FROM DUAL; 23 SELECT :NEW.Social_SecurityNum INTO NSSN FROM DUAL; 24 SELECT :NEW.Hire_Date INTO NHD FROM DUAL; 25 SELECT :NEW.End_Date INTO NEND FROM DUAL; 26 SELECT :NEW.PayRate INTO NPR FROM DUAL; 27 SELECT :NEW.Employement_Status INTO NEMS FROM DUAL;
  51. 51. 50 28 SELECT 'Insert' INTO ACT FROM DUAL; 29 30 INSERT INTO HRRecordsAudit(Employee_ID,HR_ID,Role_ID,Store_ID,DOB,Social_SecurityNum,H ire_Date, End_Date,PayRate, 31 Employement_Status,Action_Type) 32 SELECT NEMP, NHRD, NRID, NSTD, NDB,NSSN,NHD, NEND, NPR,NEMS,ACT FROM DUAL; 33 34 end HRRecordsAudit_inst_trigg; 35 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER HRRecordsAudit_upd_trigg 2 AFTER Update ON HRRecords 3 FOR EACH ROW 4 DECLARE 5 NEMP INTEGER; 6 NHRD INTEGER; 7 NRID INTEGER ; 8 NSTD INTEGER; 9 NDB DATE; 10 NSSN INTEGER; 11 NHD Date; 12 NEND Date; 13 NPR numeric(15,2); 14 NEMS varchar2(45); 15 OEMP INTEGER; 16 OHRD INTEGER; 17 ORID INTEGER ; 18 OSTD INTEGER; 19 ODB DATE; 20 OSSN INTEGER; 21 OHD Date; 22 OEND Date; 23 OPR numeric(15,2); 24 OEMS varchar2(45); 25 ACT char(20); 26 27 BEGIN 28 SELECT :NEW.Employee_ID INTO NEMP FROM DUAL; 29 SELECT :NEW.HR_ID INTO NHRD FROM DUAL; 30 SELECT :NEW.Role_ID INTO NRID FROM DUAL; 31 SELECT :NEW.Store_ID INTO NSTD FROM DUAL; 32 SELECT :NEW.DOB INTO NDB FROM DUAL; 33 SELECT :NEW.Social_SecurityNum INTO NSSN FROM DUAL; 34 SELECT :NEW.Hire_Date INTO NHD FROM DUAL; 35 SELECT :NEW.End_Date INTO NEND FROM DUAL; 36 SELECT :NEW.PayRate INTO NPR FROM DUAL; 37 SELECT :NEW.Employement_Status INTO NEMS FROM DUAL; 38 SELECT :OLD.Employee_ID INTO OEMP FROM DUAL;
  52. 52. 51 39 SELECT :OLD.HR_ID INTO OHRD FROM DUAL; 40 SELECT :OLD.Role_ID INTO ORID FROM DUAL; 41 SELECT :OLD.Store_ID INTO OSTD FROM DUAL; 42 SELECT :OLD.DOB INTO ODB FROM DUAL; 43 SELECT :OLD.Social_SecurityNum INTO OSSN FROM DUAL; 44 SELECT :OLD.Hire_Date INTO OHD FROM DUAL; 45 SELECT :OLD.End_Date INTO OEND FROM DUAL; 46 SELECT :OLD.PayRate INTO OPR FROM DUAL; 47 SELECT :OLD.Employement_Status INTO OEMS FROM DUAL; 48 SELECT 'Update' INTO ACT FROM DUAL; 49 50 INSERT INTO HRRecordsAudit(Employee_ID,HR_ID,Role_ID,Store_ID,DOB,Social_SecurityNum,H ire_Date, End_Date,PayRate, 51 Employement_Status,Old_EmployeeID,Old_HRID,Old_RoleID,Old_StoreID,Old_DOB , 52 Old_SocialSecurityNum,Old_HireDate, Old_EndDate,Old_PayRate,Old_EmployementStatus,Action_Type) 53 SELECT NEMP, NHRD, NRID, NSTD, NDB,NSSN,NHD, NEND, NPR,NEMS,OEMP, OHRD, ORID, OSTD, ODB,OSSN,OHD, OEND, OPR,OEMS, 54 ACT FROM DUAL; 55 56 end HRRecordsAudit_upd_trigg; 57 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER ManagementAudit_auditdate_trgg 2 BEFORE INSERT ON MANAGEMENTAUDIT 3 FOR EACH ROW 4 BEGIN 5 select sysdate into :New.Audit_Date from dual; 6 end HRRecordsAudit_auditdate_trgg; 7 / Trigger created. SQL> SQL> SQL> create or replace trigger ManagementAudit_audituser_trgg 2 before insert on ManagementAudit 3 for each row 4 begin 5 select user into :New.Audit_User from dual; 6 end ManagementAudit_audituser_trgg; 7 / Trigger created. SQL> SQL>
  53. 53. 52 SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER ManagementAuditt_del_trigg 2 AFTER DELETE ON Management 3 for each row 4 DECLARE 5 OMID Integer; 6 OEMP Integer; 7 OHD DATE; 8 OEND DATE; 9 ACT char(20); 10 BEGIN 11 12 SELECT :OLD.Manager_ID INTO OMID FROM DUAL; 13 SELECT :OLD.Employee_ID INTO OEMP FROM DUAL; 14 SELECT :OLD.Hire_Date INTO OHD FROM DUAL; 15 SELECT :OLD.Hire_EndDate INTO OEND FROM DUAL; 16 SELECT 'Delete' INTO ACT FROM DUAL; 17 18 INSERT INTO ManagementAudit(Old_ManagerID,Old_EmployeeID ,Old_HireDate, Old_HireEndDate ,Action_Type) 19 SELECT OMID, OEMP, OHD,OEND,ACT FROM DUAL; 20 21 22 end ManagementAuditt_del_trigg; 23 / Trigger created. SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER ManagementAuditt_inst_trigg 2 AFTER INSERT ON Management 3 for each row 4 DECLARE 5 NMID Integer; 6 NEMP Integer; 7 NHD DATE; 8 NEND DATE; 9 ACT char(20); 10 BEGIN 11 12 SELECT :NEW.Manager_ID INTO NMID FROM DUAL; 13 SELECT :NEW.Employee_ID INTO NEMP FROM DUAL; 14 SELECT :NEW.Hire_Date INTO NHD FROM DUAL; 15 SELECT :NEW.Hire_EndDate INTO NEND FROM DUAL; 16 SELECT 'Insert' INTO ACT FROM DUAL; 17 18 INSERT INTO ManagementAudit(Manager_ID,Employee_ID ,Hire_Date, Hire_EndDate ,Action_Type)
  54. 54. 53 19 SELECT NMID, NEMP, NHD,NEND,ACT FROM DUAL; 20 21 22 end ManagementAuditt_inst_trigg; 23 / Trigger created. SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER ManagementAuditt_updt_trigg 2 AFTER UPDATE ON Management 3 for each row 4 DECLARE 5 NMID Integer; 6 NEMP Integer; 7 NHD DATE; 8 NEND DATE; 9 OMID Integer; 10 OEMP Integer; 11 OHD DATE; 12 OEND DATE; 13 ACT char(20); 14 BEGIN 15 16 SELECT :NEW.Manager_ID INTO NMID FROM DUAL; 17 SELECT :NEW.Employee_ID INTO NEMP FROM DUAL; 18 SELECT :NEW.Hire_Date INTO NHD FROM DUAL; 19 SELECT :NEW.Hire_EndDate INTO NEND FROM DUAL; 20 SELECT :OLD.Manager_ID INTO OMID FROM DUAL; 21 SELECT :OLD.Employee_ID INTO OEMP FROM DUAL; 22 SELECT :OLD.Hire_Date INTO OHD FROM DUAL; 23 SELECT :OLD.Hire_EndDate INTO OEND FROM DUAL; 24 SELECT 'Update' INTO ACT FROM DUAL; 25 26 INSERT INTO ManagementAudit(Manager_ID,Employee_ID ,Hire_Date, Hire_EndDate ,Old_ManagerID,Old_EmployeeID ,Old_HireDate, Old_HireEndDate, 27 Action_Type) 28 SELECT NMID, NEMP, NHD,NEND,OMID, OEMP, OHD,OEND,ACT FROM DUAL; 29 30 end ManagementAuditt_updt_trigg; 31 32 / Trigger created. SQL> SQL> SQL> SQL> create or replace trigger storeAudit_auditdate_trgg 2 before insert on storeAudit 3 for each row 4 begin 5 select sysdate into :New.Audit_Date from dual; 6 end storeAudit_auditdate_trgg;
  55. 55. 54 7 / Trigger created. SQL> SQL> SQL> create or replace trigger storeAudit_audituser_trgg 2 before insert on storeAudit 3 for each row 4 begin 5 select user into :New.Audit_User from dual; 6 end storeAudit_audituser_trgg; 7 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER storeAudit_del_trigg 2 AFTER DELETE ON STORE 3 FOR EACH ROW 4 DECLARE 5 OSTID Integer; 6 OSSTID Integer; 7 OSMID Integer; 8 OSTN Varchar2(65); 9 OSTY Varchar2(34); 10 OSTA Varchar2(65); 11 OSTC Varchar2(45); 12 OSP Varchar2(45); 13 OSTS Varchar2(30); 14 ACT char(20); 15 BEGIN 16 SELECT :OLD.Store_ID INTO OSTID FROM DUAL; 17 SELECT :OLD.Store_StateID INTO OSSTID FROM DUAL; 18 SELECT :OLD.Store_ManagerID INTO OSMID FROM DUAL; 19 SELECT :OLD.Store_Name INTO OSTN FROM DUAL; 20 SELECT :OLD.Store_Type INTO OSTY FROM DUAL; 21 SELECT :OLD.Store_Address INTO OSTA FROM DUAL; 22 SELECT :OLD.Store_City INTO OSTC FROM DUAL; 23 SELECT :OLD.Store_Phone INTO OSP FROM DUAL; 24 SELECT :OLD.Store_Status INTO OSTS FROM DUAL; 25 SELECT 'Delete' INTO ACT FROM DUAL; 26 27 28 29 insert into storeAudit(Old_StoreID,Old_StorStateID,Old_StorManagerID,Old_StorName,Old_ StorType,Old_StorAddress,Old_StorCity,old_StorPhone,old_StorStatus, Action_Type) 30 select OSTID, OSSTID, OSMID, OSTN, OSTY,OSTA,OSTC,OSP,OSTS, ACT FROM DUAL; 31 end storeAudit_del_trigg; 32 /
  56. 56. 55 Trigger created. SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER storeAudit_inst_trigg 2 AFTER INSERT ON STORE 3 FOR EACH ROW 4 DECLARE 5 NSTID Integer; 6 NSSTID Integer; 7 NSMID Integer; 8 NSTN Varchar2(65); 9 NSTY Varchar2(34); 10 NSTA Varchar2(65); 11 NSTC Varchar2(45); 12 NSP Varchar2(45); 13 NSTS Varchar2(30); 14 ACT char(20); 15 BEGIN 16 SELECT :NEW.Store_ID INTO NSTID FROM DUAL; 17 SELECT :NEW.Store_StateID INTO NSSTID FROM DUAL; 18 SELECT :NEW.Store_ManagerID INTO NSMID FROM DUAL; 19 SELECT :NEW.Store_Name INTO NSTN FROM DUAL; 20 SELECT :NEW.Store_Type INTO NSTY FROM DUAL; 21 SELECT :NEW.Store_Address INTO NSTA FROM DUAL; 22 SELECT :NEW.Store_City INTO NSTC FROM DUAL; 23 SELECT :NEW.Store_Phone INTO NSP FROM DUAL; 24 SELECT :NEW.Store_Status INTO NSTS FROM DUAL; 25 SELECT 'Insert' INTO ACT FROM DUAL; 26 27 28 29 insert into storeAudit(Store_ID,Store_StateID,Store_ManagerID,Store_Name,Store_Type,St ore_Address,Store_City,Store_Phone,Store_Status, Action_Type) 30 select NSTID, NSSTID, NSMID, NSTN, NSTY,NSTA,NSTC,NSP,NSTS, ACT FROM DUAL; 31 end storeAudit_del_trigg; 32 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER storeAudit_upd_trigg 2 AFTER update ON STORE 3 FOR EACH ROW 4 DECLARE 5 NSTID Integer;
  57. 57. 56 6 NSSTID Integer; 7 NSMID Integer; 8 NSTN Varchar2(65); 9 NSTY Varchar2(34); 10 NSTA Varchar2(65); 11 NSTC Varchar2(45); 12 NSP Varchar2(45); 13 NSTS Varchar2(30); 14 OSTID Integer; 15 OSSTID Integer; 16 OSMID Integer; 17 OSTN Varchar2(65); 18 OSTY Varchar2(34); 19 OSTA Varchar2(65); 20 OSTC Varchar2(45); 21 OSP Varchar2(45); 22 OSTS Varchar2(30); 23 ACT char(20); 24 BEGIN 25 SELECT :NEW.Store_ID INTO NSTID FROM DUAL; 26 SELECT :NEW.Store_StateID INTO NSSTID FROM DUAL; 27 SELECT :NEW.Store_ManagerID INTO NSMID FROM DUAL; 28 SELECT :NEW.Store_Name INTO NSTN FROM DUAL; 29 SELECT :NEW.Store_Type INTO NSTY FROM DUAL; 30 SELECT :NEW.Store_Address INTO NSTA FROM DUAL; 31 SELECT :NEW.Store_City INTO NSTC FROM DUAL; 32 SELECT :NEW.Store_Phone INTO NSP FROM DUAL; 33 SELECT :NEW.Store_Status INTO NSTS FROM DUAL; 34 SELECT :OLD.Store_ID INTO OSTID FROM DUAL; 35 SELECT :OLD.Store_StateID INTO OSSTID FROM DUAL; 36 SELECT :OLD.Store_ManagerID INTO OSMID FROM DUAL; 37 SELECT :OLD.Store_Name INTO OSTN FROM DUAL; 38 SELECT :OLD.Store_Type INTO OSTY FROM DUAL; 39 SELECT :OLD.Store_Address INTO OSTA FROM DUAL; 40 SELECT :OLD.Store_City INTO OSTC FROM DUAL; 41 SELECT :OLD.Store_Phone INTO OSP FROM DUAL; 42 SELECT :OLD.Store_Status INTO OSTS FROM DUAL; 43 SELECT 'Update' INTO ACT FROM DUAL; 44 45 insert into storeAudit(Store_ID,Store_StateID,Store_ManagerID,Store_Name,Store_Type,St ore_Address,Store_City,Store_Phone,Store_Status, 46 Old_StoreID,Old_StorStateID,Old_StorManagerID,Old_StorName,Old_StorType,Ol d_StorAddress,Old_StorCity,old_StorPhone,old_StorStatus, 47 Action_Type) 48 select NSTID, NSSTID, NSMID, NSTN, NSTY,NSTA,NSTC,NSP,NSTS, OSTID, OSSTID, OSMID, OSTN, OSTY,OSTA,OSTC,OSP,OSTS, ACT FROM DUAL; 49 end storeAudit_upd_trigg; 50 / Trigger created. SQL> SQL> SQL> SQL>
  58. 58. 57 SQL> set echo off SQL> spool off; SQL> SQL> SQL> SQL> SQL> SQL> show user USER is "HOWARDDBA" SQL> SQL> SQL> SQL> ---This trigger will populate the CustomerAudit table audit date column SQL> SQL> create or replace trigger CustomerAudit_auditdate_trgg 2 before insert on CustomerAudit 3 for each row 4 begin 5 select sysdate into :New.Audit_Date from dual; 6 end CustomerAudit_auditdate_trgg; 7 / Trigger created. SQL> SQL> SQL> /*This trigger will populate the storeAudit table audit user column automatically */ Trigger created. SQL> SQL> create or replace trigger CustomerAudit_audituser_trgg 2 before insert on CustomerAudit 3 for each row 4 begin 5 select user into :New.Audit_User from dual; 6 end CustomerAudit_audituser_trgg; 7 / Trigger created. SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER CustomerAudit_del_trigg 2 AFTER DELETE ON Customer 3 FOR EACH ROW 4 DECLARE 5 OCID integer;
  59. 59. 58 6 OSTID Integer; 7 OFN Varchar2(50); 8 OMDN Varchar2(50); 9 OLN Varchar2(50); 10 OAD Varchar2(50); 11 OCIT Varchar2(45); 12 OPN Varchar2(45); 13 ODB DATE; 14 ACT CHAR(20); 15 BEGIN 16 SELECT :OLD.Customer_ID INTO OCID FROM DUAL; 17 SELECT :OLD.State_ID INTO OSTID FROM DUAL; 18 SELECT :OLD.First_Name INTO OFN FROM DUAL; 19 SELECT :OLD.Middle_Name INTO OMDN FROM DUAL; 20 SELECT :OLD.Last_Name INTO OLN FROM DUAL; 21 SELECT :OLD.Address INTO OAD FROM DUAL; 22 SELECT :OLD.City INTO OCIT FROM DUAL; 23 SELECT :OLD.Phone INTO OPN FROM DUAL; 24 SELECT :OLD.DOB INTO ODB FROM DUAL; 25 SELECT 'Delete' INTO ACT FROM DUAL; 26 27 INSERT INTO CUSTOMERAUDIT 28 (Old_CustomerID, Old_StateID ,Old_FirstName , Old_MiddleName, Old_LastName, Old_Address ,Old_City, Old_Phone, Old_DOB , Action_Type) 29 SELECT OCID,OSTID,OFN,OMDN,OLN,OAD,OCIT,OPN,ODB ,ACT FROM DUAL; 30 31 END CustomerAudit_del_trigg; 32 / Trigger created. SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER CustomerAudit_Inst_trigg 2 AFTER INSERT ON Customer 3 FOR EACH ROW 4 DECLARE 5 NCID integer; 6 NSTID Integer; 7 NFN Varchar2(50); 8 NMDN Varchar2(50); 9 NLN Varchar2(50); 10 NAD Varchar2(50); 11 NCIT Varchar2(45); 12 NPN Varchar2(45); 13 NDB DATE; 14 ACT CHAR(20); 15 BEGIN 16 SELECT :NEW.Customer_ID INTO NCID FROM DUAL; 17 SELECT :NEW.State_ID INTO NSTID FROM DUAL; 18 SELECT :NEW.First_Name INTO NFN FROM DUAL; 19 SELECT :NEW.Middle_Name INTO NMDN FROM DUAL; 20 SELECT :NEW.Last_Name INTO NLN FROM DUAL; 21 SELECT :NEW.Address INTO NAD FROM DUAL; 22 SELECT :NEW.City INTO NCIT FROM DUAL;
  60. 60. 59 23 SELECT :NEW.Phone INTO NPN FROM DUAL; 24 SELECT :NEW.DOB INTO NDB FROM DUAL; 25 SELECT 'Insert' INTO ACT FROM DUAL; 26 27 INSERT INTO CUSTOMERAUDIT 28 (Customer_ID, State_ID ,First_Name , Middle_Name, Last_Name, Address ,City, Phone, DOB , Action_Type) 29 SELECT NCID,NSTID,NFN,NMDN,NLN,NAD,NCIT,NPN,NDB ,ACT FROM DUAL; 30 31 END CustomerAudit_Inst_trigg; 32 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER CustomerAudit_Updt_trigg 2 AFTER UPDATE ON Customer 3 FOR EACH ROW 4 DECLARE 5 NCID integer; 6 NSTID Integer; 7 NFN Varchar2(50); 8 NMDN Varchar2(50); 9 NLN Varchar2(50); 10 NAD Varchar2(50); 11 NCIT Varchar2(45); 12 NPN Varchar2(45); 13 NDB DATE; 14 OCID integer; 15 OSTID Integer; 16 OFN Varchar2(50); 17 OMDN Varchar2(50); 18 OLN Varchar2(50); 19 OAD Varchar2(50); 20 OCIT Varchar2(45); 21 OPN Varchar2(45); 22 ODB DATE; 23 ACT CHAR(20); 24 BEGIN 25 SELECT :NEW.Customer_ID INTO NCID FROM DUAL; 26 SELECT :NEW.State_ID INTO NSTID FROM DUAL; 27 SELECT :NEW.First_Name INTO NFN FROM DUAL; 28 SELECT :NEW.Middle_Name INTO NMDN FROM DUAL; 29 SELECT :NEW.Last_Name INTO NLN FROM DUAL; 30 SELECT :NEW.Address INTO NAD FROM DUAL; 31 SELECT :NEW.City INTO NCIT FROM DUAL; 32 SELECT :NEW.Phone INTO NPN FROM DUAL; 33 SELECT :NEW.DOB INTO NDB FROM DUAL; 34 SELECT :OLD.Customer_ID INTO OCID FROM DUAL; 35 SELECT :OLD.State_ID INTO OSTID FROM DUAL; 36 SELECT :OLD.First_Name INTO OFN FROM DUAL; 37 SELECT :OLD.Middle_Name INTO OMDN FROM DUAL; 38 SELECT :OLD.Last_Name INTO OLN FROM DUAL;
  61. 61. 60 39 SELECT :OLD.Address INTO OAD FROM DUAL; 40 SELECT :OLD.City INTO OCIT FROM DUAL; 41 SELECT :OLD.Phone INTO OPN FROM DUAL; 42 SELECT :OLD.DOB INTO ODB FROM DUAL; 43 SELECT 'Update' INTO ACT FROM DUAL; 44 45 INSERT INTO CUSTOMERAUDIT 46 (Customer_ID, State_ID ,First_Name , Middle_Name, Last_Name, Address ,City, Phone, DOB , Old_CustomerID, Old_StateID ,Old_FirstName , Old_MiddleName, Old_LastName, 47 Old_Address ,Old_City, Old_Phone, Old_DOB ,Action_Type) 48 SELECT NCID,NSTID,NFN,NMDN,NLN,NAD,NCIT,NPN,NDB ,OCID,OSTID,OFN,OMDN,OLN,OAD,OCIT,OPN,ODB,ACT FROM DUAL; 49 50 END CustomerAudit_Updt_trigg; 51 / Trigger created. SQL> create or replace trigger ProdCatAudit_auddate_trgg 2 before insert on ProductCategoryAudit 3 for each row 4 begin 5 select sysdate into :New.Audit_Date from dual; 6 end ProdCatAudit_auddate_trgg; 7 / Trigger created. SQL> SQL> SQL> SQL> create or replace trigger ProdCatAudit_audituser_trgg 2 before insert on ProductCategoryAudit 3 for each row 4 begin 5 select user into :New.Audit_User from dual; 6 end ProdCatAudit_audituser_trgg; 7 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER ProductCategoryAudit_del_trigg 2 AFTER DELETE ON ProductCategory 3 FOR EACH ROW 4 DECLARE 5 OPCID Integer; 6 OPCN Varchar2(45);
  62. 62. 61 7 OPCD CLOB; 8 ACT Char(20); 9 BEGIN 10 SELECT :OLD.Product_CategoryID INTO OPCID FROM DUAL; 11 SELECT :OLD.Category_Name INTO OPCN FROM DUAL; 12 SELECT :OLD.Category_Description INTO OPCD FROM DUAL; 13 SELECT 'Delete' Into ACT FROM DUAL; 14 15 16 INSERT INTO ProductCategoryAudit (Old_ProdCategoryID,Old_CategoryName,Old_CategoryDescription , Action_Type ) 17 SELECT OPCID,OPCN,OPCD, ACT 18 19 FROM DUAL; 20 END ProductCategoryAudit_del_trigg; 21 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER ProdCategoryAudit_inst_trigg 2 AFTER INSERT ON ProductCategory 3 FOR EACH ROW 4 DECLARE 5 NPCID Integer; 6 NPCN Varchar2(45); 7 NPCD CLOB; 8 ACT Char(20); 9 BEGIN 10 SELECT :NEW.Product_CategoryID INTO NPCID FROM DUAL; 11 SELECT :NEW.Category_Name INTO NPCN FROM DUAL; 12 SELECT :NEW.Category_Description INTO NPCD FROM DUAL; 13 SELECT 'Insert' Into ACT FROM DUAL; 14 15 16 INSERT INTO ProductCategoryAudit (Product_CategoryID,Category_Name,Category_Description , Action_Type ) 17 SELECT NPCID,NPCN,NPCD, ACT 18 19 FROM DUAL; 20 END ProdCategoryAudit_inst_trigg; 21 / Trigger created. SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER ProdCategoryAudit_upt_trigg 2 AFTER update ON ProductCategory 3 FOR EACH ROW
  63. 63. 62 4 DECLARE 5 NPCID Integer; 6 NPCN Varchar2(45); 7 NPCD CLOB; 8 ACT Char(20); 9 OPCID Integer; 10 OPCN Varchar2(45); 11 OPCD CLOB; 12 BEGIN 13 SELECT :NEW.Product_CategoryID INTO NPCID FROM DUAL; 14 SELECT :NEW.Category_Name INTO NPCN FROM DUAL; 15 SELECT :NEW.Category_Description INTO NPCD FROM DUAL; 16 SELECT :OLD.Product_CategoryID INTO OPCID FROM DUAL; 17 SELECT :OLD.Category_Name INTO OPCN FROM DUAL; 18 SELECT :OLD.Category_Description INTO OPCD FROM DUAL; 19 SELECT 'Update' Into ACT FROM DUAL; 20 21 22 INSERT INTO ProductCategoryAudit (Product_CategoryID,Category_Name,Category_Description , 23 Old_ProdCategoryID,Old_CategoryName,Old_CategoryDescription, 24 Action_Type ) 25 SELECT NPCID,NPCN,NPCD,OPCID,OPCN,OPCD, ACT 26 27 FROM DUAL; 28 END ProdCategoryAudit_upt_trigg; 29 / Trigger created. SQL> SQL> SQL> create or replace trigger productAudit_auditdate_trgg 2 before insert on productAudit 3 for each row 4 begin 5 select sysdate into :New.Audit_Date from dual; 6 end productAudit_auditdate_trgg; 7 / Trigger created. SQL> SQL> SQL> SQL> create or replace trigger productAudit_audituser_trgg 2 before insert on productAudit 3 for each row 4 begin 5 select user into :New.Audit_User from dual; 6 end productAudit_audituser_trgg; 7 / Trigger created. SQL> SQL>
  64. 64. 63 SQL> SQL> SQL> CREATE OR REPLACE TRIGGER productAudit_del_trigg 2 AFTER DELETE ON PRODUCT 3 FOR EACH ROW 4 DECLARE 5 OPID Integer; 6 OPCID Integer; 7 OPN Varchar2(50); 8 OPC Varchar2(35); 9 OPS Varchar2(35); 10 OPW Varchar2(45); 11 OPD CLOB; 12 ACT Char(20); 13 14 BEGIN 15 SELECT :OLD.Product_ID INTO OPID FROM DUAL; 16 SELECT :OLD.Product_CategoryID INTO OPCID FROM DUAL; 17 SELECT :OLD.Product_Name INTO OPN FROM DUAL; 18 SELECT :OLD.Product_Color INTO OPC FROM DUAL; 19 SELECT :OLD.Product_Size INTO OPS FROM DUAL; 20 SELECT :OLD.Product_Weight INTO OPW FROM DUAL; 21 SELECT :OLD.Product_Description INTO OPD FROM DUAL; 22 SELECT 'Delete' INTO ACT FROM DUAL; 23 24 25 INSERT INTO productAudit 26 (Old_ProductID,Old_ProdCategoryID,Old_ProdName,Old_ProdColor,Old_ProdSize, Old_ProdWeight,Old_ProdDescription, Action_Type) 27 SELECT OPID,OPCID, OPN, OPC,OPS,OPW,OPD, ACT FROM DUAL; 28 END productAudit_del_trigg; 29 / Trigger created. SQL> SQL> SQL> CREATE OR REPLACE TRIGGER productAudit_Inst_trigg 2 AFTER INSERT ON PRODUCT 3 FOR EACH ROW 4 DECLARE 5 NPID Integer; 6 NPCID Integer; 7 NPN Varchar2(50); 8 NPC Varchar2(35); 9 NPS Varchar2(35); 10 NPW Varchar2(45); 11 NPD CLOB; 12 ACT Char(20); 13 14 BEGIN 15 SELECT :NEW.Product_ID INTO NPID FROM DUAL; 16 SELECT :NEW.Product_CategoryID INTO NPCID FROM DUAL; 17 SELECT :NEW.Product_Name INTO NPN FROM DUAL; 18 SELECT :NEW.Product_Color INTO NPC FROM DUAL; 19 SELECT :NEW.Product_Size INTO NPS FROM DUAL;
  65. 65. 64 20 SELECT :NEW.Product_Weight INTO NPW FROM DUAL; 21 SELECT :NEW.Product_Description INTO NPD FROM DUAL; 22 SELECT 'Insert' INTO ACT FROM DUAL; 23 24 25 INSERT INTO productAudit 26 (Product_ID,Product_CategoryID,Product_Name,Product_Color,Product_Size,Pro duct_Weight,Product_Description, Action_Type) 27 SELECT NPID,NPCID, NPN, NPC,NPS,NPW,NPD, ACT FROM DUAL; 28 END productAudit_Inst_trigg; 29 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER productAudit_updt_trigg 2 AFTER update ON PRODUCT 3 FOR EACH ROW 4 DECLARE 5 NPID Integer; 6 NPCID Integer; 7 NPN Varchar2(50); 8 NPC Varchar2(35); 9 NPS Varchar2(35); 10 NPW Varchar2(45); 11 NPD CLOB; 12 OPID Integer; 13 OPCID Integer; 14 OPN Varchar2(50); 15 OPC Varchar2(35); 16 OPS Varchar2(35); 17 OPW Varchar2(45); 18 OPD CLOB; 19 ACT Char(20); 20 21 BEGIN 22 SELECT :NEW.Product_ID INTO NPID FROM DUAL; 23 SELECT :NEW.Product_CategoryID INTO NPCID FROM DUAL; 24 SELECT :NEW.Product_Name INTO NPN FROM DUAL; 25 SELECT :NEW.Product_Color INTO NPC FROM DUAL; 26 SELECT :NEW.Product_Size INTO NPS FROM DUAL; 27 SELECT :NEW.Product_Weight INTO NPW FROM DUAL; 28 SELECT :NEW.Product_Description INTO NPD FROM DUAL; 29 SELECT :OLD.Product_ID INTO OPID FROM DUAL; 30 SELECT :OLD.Product_CategoryID INTO OPCID FROM DUAL; 31 SELECT :OLD.Product_Name INTO OPN FROM DUAL; 32 SELECT :OLD.Product_Color INTO OPC FROM DUAL; 33 SELECT :OLD.Product_Size INTO OPS FROM DUAL; 34 SELECT :OLD.Product_Weight INTO OPW FROM DUAL; 35 SELECT :OLD.Product_Description INTO OPD FROM DUAL; 36 SELECT 'Update' INTO ACT FROM DUAL; 37
  66. 66. 65 38 39 INSERT INTO productAudit 40 (Product_ID,Product_CategoryID,Product_Name,Product_Color,Product_Size,Pro duct_Weight,Product_Description, 41 Old_ProductID,Old_ProdCategoryID,Old_ProdName,Old_ProdColor,Old_ProdSize,O ld_ProdWeight,Old_ProdDescription, 42 Action_Type) 43 SELECT NPID,NPCID, NPN, NPC,NPS,NPW,NPD, OPID,OPCID, OPN, OPC,OPS,OPW,OPD, 44 ACT FROM DUAL; 45 END productAudit_updt_trigg; 46 / Trigger created. SQL> set echo off; SQL> spool off; SQL> SQL> SQL> SQL> create or replace trigger PaymentCopAudit_auditdate_trgg 2 before insert on PaymentCopAudit 3 for each row 4 begin 5 select sysdate into :New.Audit_Date from dual; 6 end PaymentCopAudit_auditdate_trgg; 7 / Trigger created. SQL> SQL> SQL> create or replace trigger PaymentCopAudit_audituser_trgg 2 before insert on PaymentCopAudit 3 for each row 4 begin 5 select user into :New.Audit_User from dual; 6 end PaymentCopAudit_audituser_trgg; 7 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER PayCopAudit_del_trigg
  67. 67. 66 2 AFTER DELETE ON PaymentCop 3 FOR EACH ROW 4 DECLARE 5 OPID Integer; 6 OPCNE Varchar2(50); 7 OPPT Varchar2(45); 8 OPCD Date; 9 OPST varchar2(25); 10 OPCN Integer; 11 OPCE Date; 12 ACT Char(20); 13 14 BEGIN 15 SELECT :OLD.PAYMENT_ID INTO OPID FROM DUAL; 16 SELECT :OLD.PAYMENT_COPNAME INTO OPCNE FROM DUAL; 17 SELECT :OLD.PAYMENT_TYPE INTO OPPT FROM DUAL; 18 SELECT :OLD.PAYMENT_CREATEDDATE INTO OPCD FROM DUAL; 19 SELECT :OLD.PAYMENT_STATUS INTO OPST FROM DUAL; 20 SELECT :OLD.PAYMENTCARD_NUMBER INTO OPCN FROM DUAL; 21 SELECT :OLD.PAYMENT_EXPDATE INTO OPCE FROM DUAL; 22 SELECT 'Delete' INTO ACT From DUAL; 23 24 INSERT INTO PaymentCopAudit(Old_Payid,Old_PayCopName,old_PayType,Old_PayCreatedDate,Ol d_PayStatus,Old_PayCard_Number,OLD_PCARD_EXPDATE 25 , Action_Type) 26 SELECT OPID,OPCNE,OPPT,OPCD,OPST, OPCN,OPCE, ACT 27 28 FROM DUAL; 29 end PayCopAudit_del_trigg; 30 / Trigger created. SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER PayCopAudit_Inst_trigg 2 AFTER INSERT ON PaymentCop 3 FOR EACH ROW 4 DECLARE 5 NPID Integer; 6 NPCNE Varchar2(50); 7 NPPT Varchar2(45); 8 NPCD Date; 9 NPST varchar2(25); 10 NPCN Integer; 11 NPCE Date; 12 ACT Char(20); 13 14 BEGIN 15 SELECT :NEW.PAYMENT_ID INTO NPID FROM DUAL; 16 SELECT :NEW.PAYMENT_COPNAME INTO NPCNE FROM DUAL; 17 SELECT :NEW.PAYMENT_TYPE INTO NPPT FROM DUAL; 18 SELECT :NEW.PAYMENT_CREATEDDATE INTO NPCD FROM DUAL; 19 SELECT :NEW.PAYMENT_STATUS INTO NPST FROM DUAL;
  68. 68. 67 20 SELECT :NEW.PAYMENTCARD_NUMBER INTO NPCN FROM DUAL; 21 SELECT :NEW.PAYMENT_EXPDATE INTO NPCE FROM DUAL; 22 SELECT 'Insert' INTO ACT From DUAL; 23 24 INSERT INTO PaymentCopAudit(Payment_id,Payment_CopName,Payment_Type,Payment_CreatedDat e,Payment_Status,PaymentCard_Number,PAYMENT_EXPDATE 25 , Action_Type) 26 SELECT NPID,NPCNE,NPPT,NPCD,NPST, NPCN,NPCE, ACT 27 28 FROM DUAL; 29 end PayCopAudit_Inst_trigg; 30 / Trigger created. SQL> SQL> CREATE OR REPLACE TRIGGER PayCopAudit_upd_trigg 2 AFTER UPDATE ON PaymentCop 3 FOR EACH ROW 4 DECLARE 5 NPID Integer; 6 NPCNE Varchar2(50); 7 NPPT Varchar2(45); 8 NPCD Date; 9 NPST varchar2(25); 10 NPCN Integer; 11 NPCE Date; 12 OPID Integer; 13 OPCNE Varchar2(50); 14 OPPT Varchar2(45); 15 OPCD Date; 16 OPST varchar2(25); 17 OPCN Integer; 18 OPCE Date; 19 ACT Char(20); 20 21 BEGIN 22 SELECT :NEW.PAYMENT_ID INTO NPID FROM DUAL; 23 SELECT :NEW.PAYMENT_COPNAME INTO NPCNE FROM DUAL; 24 SELECT :NEW.PAYMENT_TYPE INTO NPPT FROM DUAL; 25 SELECT :NEW.PAYMENT_CREATEDDATE INTO NPCD FROM DUAL; 26 SELECT :NEW.PAYMENT_STATUS INTO NPST FROM DUAL; 27 SELECT :NEW.PAYMENTCARD_NUMBER INTO NPCN FROM DUAL; 28 SELECT :NEW.PAYMENT_EXPDATE INTO NPCE FROM DUAL; 29 SELECT :OLD.PAYMENT_ID INTO OPID FROM DUAL; 30 SELECT :OLD.PAYMENT_COPNAME INTO OPCNE FROM DUAL; 31 SELECT :OLD.PAYMENT_TYPE INTO OPPT FROM DUAL; 32 SELECT :OLD.PAYMENT_CREATEDDATE INTO OPCD FROM DUAL; 33 SELECT :OLD.PAYMENT_STATUS INTO OPST FROM DUAL; 34 SELECT :OLD.PAYMENTCARD_NUMBER INTO OPCN FROM DUAL; 35 SELECT :OLD.PAYMENT_EXPDATE INTO OPCE FROM DUAL; 36 SELECT 'Update' INTO ACT From DUAL; 37 38 INSERT INTO PaymentCopAudit(Payment_id,Payment_CopName,Payment_Type,Payment_CreatedDat e,Payment_Status,PaymentCard_Number,PAYMENT_EXPDATE ,
  69. 69. 68 39 Old_Payid,Old_PayCopName,old_PayType,Old_PayCreatedDate,Old_PayStatus,Old_ PayCard_Number,OLD_PCARD_EXPDATE 40 , Action_Type) 41 SELECT NPID,NPCNE,NPPT,NPCD,NPST, NPCN,NPCE, OPID,OPCNE,OPPT,OPCD,OPST, OPCN,OPCE, ACT 42 43 FROM DUAL; 44 end PayCopAudit_upd_trigg; 45 / Trigger created. SQL> SQL> SQL> SQL> create or replace trigger ReceiptAudit_auditdate_trgg 2 before insert on ReceiptAudit 3 for each row 4 begin 5 select sysdate into :New.Audit_Date from dual; 6 end ReceiptAudit_auditdate_trgg; 7 / Trigger created. SQL> SQL> SQL> SQL> create or replace trigger ReceiptAudit_audituser_trgg 2 before insert on ReceiptAudit 3 for each row 4 begin 5 select user into :New.Audit_User from dual; 6 end ReceiptAudit_audituser_trgg; 7 / Trigger created. SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER ReceiptAudit_delt_trigg 2 AFTER DELETE ON Receipt 3 FOR EACH ROW 4 DECLARE 5 ORCIPD INTEGER; 6 OSTID INTEGER; 7 OEMPD INTEGER; 8 OCUID INTEGER; 9 OSTRID INTEGER; 10 ORPID INTEGER; 11 ORPTX DECIMAL(8,2); 12 OQT INTEGER; 13 OPID Integer; 14 ORFMT DECIMAL(8,2);
  70. 70. 69 15 ORAMT DECIMAL(8,2); 16 ORIDT DATE; 17 ORPYID INTEGER; 18 ACT Char(20); 19 20 BEGIN 21 SELECT :OLD.RECEIPT_ID INTO ORCIPD FROM DUAL; 22 SELECT :OLD.STATE_ID INTO OSTID FROM DUAL; 23 SELECT :OLD.EMPLOYEE_ID INTO OEMPD FROM DUAL; 24 SELECT :OLD.CUSTOMER_ID INTO OCUID FROM DUAL; 25 SELECT :OLD.STORE_ID INTO OSTRID FROM DUAL; 26 SELECT :OLD.PRODUCT_ID INTO ORPID FROM DUAL; 27 SELECT :OLD.RECEIPT_TAX INTO ORPTX FROM DUAL; 28 SELECT :OLD.QTY INTO OQT FROM DUAL; 29 SELECT :OLD.RECEIPT_FINALAMT INTO ORFMT FROM DUAL; 30 SELECT :OLD.RECEIPT_AMOUNT INTO ORAMT FROM DUAL; 31 SELECT :OLD.RECEIPT_DATE INTO ORIDT FROM DUAL; 32 SELECT :OLD.Payment_ID INTO ORPYID FROM DUAL; 33 SELECT 'Delete' INTO ACT From DUAL; 34 35 insert into ReceiptAudit 36 (OLD_RECEIPTID , OLD_STATEID ,OLD_EMPLOYEEID,OLD_CUSTOMERID,OLD_STOREID, OLD_PRODID , OLD_RECEPTTAX, 37 OLD_QTY, OLD_RECEIPTDATE, OLD_RECPTFINALAMT ,OLD_RECPTAMT,OLD_PAYMENTID, 38 Action_Type) 39 SELECT ORCIPD, OSTID, OEMPD, OCUID, OSTRID,ORPID,ORPTX, OQT, ORIDT, ORFMT, ORAMT, ORPYID,ACT 40 41 42 from dual; 43 44 45 end ReceiptAudit_delt_trigg; 46 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER ReceiptAudit_inst_trigg 2 AFTER insert ON Receipt 3 FOR EACH ROW 4 DECLARE 5 NRCIPD INTEGER; 6 NSTID INTEGER; 7 NEMPD INTEGER; 8 NCUID INTEGER; 9 NSTRID INTEGER; 10 NRPID INTEGER; 11 NRPTX DECIMAL(8,2); 12 NQT INTEGER; 13 NPID Integer;
  71. 71. 70 14 NRFMT DECIMAL(8,2); 15 NRAMT DECIMAL(8,2); 16 NRIDT DATE; 17 NRPYID INTEGER; 18 ACT Char(20); 19 20 BEGIN 21 SELECT :NEW.RECEIPT_ID INTO NRCIPD FROM DUAL; 22 SELECT :NEW.STATE_ID INTO NSTID FROM DUAL; 23 SELECT :NEW.EMPLOYEE_ID INTO NEMPD FROM DUAL; 24 SELECT :NEW.CUSTOMER_ID INTO NCUID FROM DUAL; 25 SELECT :NEW.STORE_ID INTO NSTRID FROM DUAL; 26 SELECT :NEW.PRODUCT_ID INTO NRPID FROM DUAL; 27 SELECT :NEW.RECEIPT_TAX INTO NRPTX FROM DUAL; 28 SELECT :NEW.QTY INTO NQT FROM DUAL; 29 SELECT :NEW.RECEIPT_FINALAMT INTO NRFMT FROM DUAL; 30 SELECT :NEW.RECEIPT_AMOUNT INTO NRAMT FROM DUAL; 31 SELECT :NEW.RECEIPT_DATE INTO NRIDT FROM DUAL; 32 SELECT :NEW.Payment_ID INTO NRPYID FROM DUAL; 33 SELECT 'Insert' INTO ACT From DUAL; 34 35 insert into ReceiptAudit 36 (RECEIPT_ID , STATE_ID ,EMPLOYEE_ID,CUSTOMER_ID,STORE_ID, PRODUCT_ID , RECEIPT_TAX, 37 QTY, RECEIPT_DATE, RECEIPT_FINALAMT ,RECEIPT_AMOUNT,Payment_ID, 38 Action_Type) 39 SELECT NRCIPD, NSTID, NEMPD, NCUID, NSTRID,NRPID,NRPTX, NQT, NRIDT, NRFMT, NRAMT, NRPYID,ACT 40 41 42 from dual; 43 44 45 end ReceiptAudit_inst_trigg; 46 / Trigger created. SQL> SQL> SQL> SQL> CREATE OR REPLACE TRIGGER ReceiptAudit_updt_trigg 2 AFTER update ON Receipt 3 FOR EACH ROW 4 DECLARE 5 NRCIPD INTEGER; 6 NSTID INTEGER; 7 NEMPD INTEGER; 8 NCUID INTEGER; 9 NSTRID INTEGER; 10 NRPID INTEGER; 11 NRPTX DECIMAL(8,2); 12 NQT INTEGER; 13 NPID Integer; 14 NRFMT DECIMAL(8,2); 15 NRAMT DECIMAL(8,2); 16 NRIDT DATE;
  72. 72. 71 17 NRPYID INTEGER; 18 ORCIPD INTEGER; 19 OSTID INTEGER; 20 OEMPD INTEGER; 21 OCUID INTEGER; 22 OSTRID INTEGER; 23 ORPID INTEGER; 24 ORPTX DECIMAL(8,2); 25 OQT INTEGER; 26 OPID Integer; 27 ORFMT DECIMAL(8,2); 28 ORAMT DECIMAL(8,2); 29 ORIDT DATE; 30 ORPYID INTEGER; 31 ACT Char(20); 32 33 BEGIN 34 SELECT :NEW.RECEIPT_ID INTO NRCIPD FROM DUAL; 35 SELECT :NEW.STATE_ID INTO NSTID FROM DUAL; 36 SELECT :NEW.EMPLOYEE_ID INTO NEMPD FROM DUAL; 37 SELECT :NEW.CUSTOMER_ID INTO NCUID FROM DUAL; 38 SELECT :NEW.STORE_ID INTO NSTRID FROM DUAL; 39 SELECT :NEW.PRODUCT_ID INTO NRPID FROM DUAL; 40 SELECT :NEW.RECEIPT_TAX INTO NRPTX FROM DUAL; 41 SELECT :NEW.QTY INTO NQT FROM DUAL; 42 SELECT :NEW.RECEIPT_FINALAMT INTO NRFMT FROM DUAL; 43 SELECT :NEW.RECEIPT_AMOUNT INTO NRAMT FROM DUAL; 44 SELECT :NEW.RECEIPT_DATE INTO NRIDT FROM DUAL; 45 SELECT :NEW.Payment_ID INTO NRPYID FROM DUAL; 46 SELECT :OLD.RECEIPT_ID INTO ORCIPD FROM DUAL; 47 SELECT :OLD.STATE_ID INTO OSTID FROM DUAL; 48 SELECT :OLD.EMPLOYEE_ID INTO OEMPD FROM DUAL; 49 SELECT :OLD.CUSTOMER_ID INTO OCUID FROM DUAL; 50 SELECT :OLD.STORE_ID INTO OSTRID FROM DUAL; 51 SELECT :OLD.PRODUCT_ID INTO ORPID FROM DUAL; 52 SELECT :OLD.RECEIPT_TAX INTO ORPTX FROM DUAL; 53 SELECT :OLD.QTY INTO OQT FROM DUAL; 54 SELECT :OLD.RECEIPT_FINALAMT INTO ORFMT FROM DUAL; 55 SELECT :OLD.RECEIPT_AMOUNT INTO ORAMT FROM DUAL; 56 SELECT :OLD.RECEIPT_DATE INTO ORIDT FROM DUAL; 57 SELECT :OLD.Payment_ID INTO ORPYID FROM DUAL; 58 SELECT 'Update' INTO ACT From DUAL; 59 60 insert into ReceiptAudit 61 (RECEIPT_ID , STATE_ID ,EMPLOYEE_ID,CUSTOMER_ID,STORE_ID, PRODUCT_ID , RECEIPT_TAX, 62 QTY, RECEIPT_DATE, RECEIPT_FINALAMT ,RECEIPT_AMOUNT,Payment_ID, 63 OLD_RECEIPTID , OLD_STATEID ,OLD_EMPLOYEEID,OLD_CUSTOMERID,OLD_STOREID, OLD_PRODID , OLD_RECEPTTAX, 64 OLD_QTY, OLD_RECEIPTDATE, OLD_RECPTFINALAMT ,OLD_RECPTAMT,OLD_PAYMENTID, 65 Action_Type) 66 SELECT NRCIPD, NSTID, NEMPD, NCUID, NSTRID,NRPID,NRPTX, NQT, NRIDT, NRFMT, NRAMT, NRPYID, 67 ORCIPD, OSTID, OEMPD, OCUID, OSTRID,ORPID,ORPTX, OQT, ORIDT, ORFMT, ORAMT, ORPYID, 68 ACT
  73. 73. 72 69 70 71 from dual; 72 73 74 end ReceiptAudit_updt_trigg; 75 / Trigger created. SQL> SQL> SQL> SQL> SQL> create or replace trigger shippingcoAudit_auditdate_trgg 2 before insert on shippingcoAudit 3 for each row 4 begin 5 select sysdate into :New.Audit_Date from dual; 6 end shippingcoAudit_auditdate_trgg; 7 / Trigger created. SQL> SQL> SQL> SQL> create or replace trigger shippingcoAudit_audituser_trgg 2 before insert on shippingcoAudit 3 for each row 4 begin 5 select user into :New.Audit_User from dual; 6 end shippingcoAudit_audituser_trgg; 7 / Trigger created. SQL> SQL> SQL> create or replace trigger shipcoAudit_del_trigg 2 after delete on shippingco 3 for each row 4 DECLARE 5 OSID integer; 6 OSNM Varchar2(50); 7 OSTU char(25); 8 OCRDT date; 9 ACT CHAR(20); 10 BEGIN 11 SELECT :OLD.SHIPPER_ID INTO OSID FROM DUAL; 12 SELECT :OLD.SHIPPER_NAME INTO OSNM FROM DUAL; 13 SELECT :OLD.STATUS INTO OSTU FROM DUAL; 14 SELECT :OLD.CREATE_DATE INTO OCRDT FROM DUAL; 15 SELECT 'Delete' INTO ACT FROM DUAL; 16
  74. 74. 73 17 INSERT INTO shippingcoAudit(Old_shipperid,old_ShipperName,old_status,old_Create_date,A ction_Type) 18 SELECT OSID, OSNM, OSTU, OCRDT, ACT FROM DUAL; 19 END shipcoAudit_del_trigg; 20 / Trigger created. SQL> SQL> SQL> SQL> create or replace trigger shipcoAudit_inst_trigg 2 after insert on shippingco 3 for each row 4 DECLARE 5 NSID integer; 6 NSNM Varchar2(50); 7 NSTU char(25); 8 NCRDT date; 9 ACT CHAR(20); 10 BEGIN 11 SELECT :NEW.SHIPPER_ID INTO NSID FROM DUAL; 12 SELECT :NEW.SHIPPER_NAME INTO NSNM FROM DUAL; 13 SELECT :NEW.STATUS INTO NSTU FROM DUAL; 14 SELECT :NEW.CREATE_DATE INTO NCRDT FROM DUAL; 15 SELECT 'Insert' INTO ACT FROM DUAL; 16 17 INSERT INTO shippingcoAudit(SHIPPER_ID,SHIPPER_NAME,STATUS,CREATE_DATE,Action_Type) 18 SELECT NSID, NSNM, NSTU, NCRDT, ACT FROM DUAL; 19 END shipcoAudit_inst_trigg; 20 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> create or replace trigger shipcoAudit_updt_trigg 2 after update on shippingco 3 for each row 4 DECLARE 5 NSID integer; 6 NSNM Varchar2(50); 7 NSTU char(25); 8 NCRDT date; 9 OSID integer; 10 OSNM Varchar2(50); 11 OSTU char(25); 12 OCRDT date; 13 ACT CHAR(20); 14 BEGIN 15 SELECT :NEW.SHIPPER_ID INTO NSID FROM DUAL; 16 SELECT :NEW.SHIPPER_NAME INTO NSNM FROM DUAL;
  75. 75. 74 17 SELECT :NEW.STATUS INTO NSTU FROM DUAL; 18 SELECT :NEW.CREATE_DATE INTO NCRDT FROM DUAL; 19 SELECT 'Update' INTO ACT FROM DUAL; 20 SELECT :OLD.SHIPPER_ID INTO OSID FROM DUAL; 21 SELECT :OLD.SHIPPER_NAME INTO OSNM FROM DUAL; 22 SELECT :OLD.STATUS INTO OSTU FROM DUAL; 23 SELECT :OLD.CREATE_DATE INTO OCRDT FROM DUAL; 24 INSERT INTO shippingcoAudit(SHIPPER_ID,SHIPPER_NAME,STATUS,CREATE_DATE, 25 Old_shipperid,old_ShipperName,old_status,old_Create_date, 26 Action_Type) 27 SELECT NSID, NSNM, NSTU, NCRDT, OSID, OSNM, OSTU, OCRDT, 28 ACT FROM DUAL; 29 END shipcoAudit_updt_trigg; 30 / Trigger created. SQL> SQL> create or replace trigger shippmentAudit_auditdate_trgg 2 before insert on shipmentaudit 3 for each row 4 begin 5 select sysdate into :New.Audit_Date from dual; 6 end shippmentAudit_auditdate_trgg; 7 / Trigger created. SQL> SQL> SQL> SQL> create or replace trigger shippmentAudit_audituser_trgg 2 before insert on shipmentaudit 3 for each row 4 begin 5 select user into :New.Audit_User from dual; 6 end shippmentAudit_audituser_trgg; 7 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> create or replace trigger shippmentAudit_del_trigg 2 after delete on shipment 3 for each row 4 DECLARE 5 6 OLSHIPID NUMBER(38); 7 OSHIPPERID NUMBER(38);
  76. 76. 75 8 OSTID NUMBER(38); 9 ORPID NUMBER(38); 10 OSHIPDATE DATE; 11 OSHIPENDDATE DATE; 12 ORVEDATE DATE; 13 ONAME VARCHAR2(55); 14 OADSS VARCHAR2(55) ; 15 OCIT VARCHAR2(55) ; 16 OLDSHIPPINGAMT NUMBER(38); 17 OSHIPPINGTYPE CHAR(35) ; 18 ACT CHAR(20); 19 20 begin 21 22 SELECT :OLD.SHIPPING_ID INTO OLSHIPID FROM DUAL; 23 SELECT :OLD.SHIPPER_ID INTO OSHIPPERID FROM DUAL; 24 SELECT :OLD.STATE_ID INTO OSTID FROM DUAL; 25 SELECT :OLD.RECEIPT_ID INTO ORPID FROM DUAL; 26 SELECT :OLD.SHIP_DATE INTO OSHIPDATE FROM DUAL; 27 SELECT :OLD.SHIP_ENDDATE INTO OSHIPENDDATE FROM DUAL; 28 SELECT :OLD.RECEIVE_DATE INTO ORVEDATE FROM DUAL; 29 SELECT :OLD.NAME INTO ONAME FROM DUAL; 30 SELECT :OLD.ADDRESS INTO OADSS FROM DUAL; 31 SELECT :OLD.CITY INTO OCIT FROM DUAL; 32 SELECT :OLD.SHIPPING_AMOUNT INTO OLDSHIPPINGAMT FROM DUAL; 33 SELECT :OLD.SHIPPING_TYPE INTO OSHIPPINGTYPE FROM DUAL; 34 SELECT 'Delete' INTO ACT From Dual; 35 36 37 insert into shipmentaudit 38 (old_shippingid,old_shipperid, old_stateid, old_ReceiptID, old_shipdate ,old_shipenddate, old_receivedate, 39 old_Name, old_Address, old_City, old_shippingamt,old_shippingtype,Action_Type) 40 select OLSHIPID, OSHIPPERID, OSTID, ORPID, OSHIPDATE, OSHIPENDDATE,ORVEDATE,ONAME, OADSS, OCIT,OLDSHIPPINGAMT, 41 OSHIPPINGTYPE, ACT 42 from dual; 43 end shippmentAudit_del_trigg; 44 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> SQL> create or replace trigger shippmentAudit_inst_trigg 2 after insert on shipment 3 for each row 4 DECLARE 5 6 NLSHIPID NUMBER(38); 7 NSHIPPERID NUMBER(38); 8 NSTID NUMBER(38);
  77. 77. 76 9 NRPID NUMBER(38); 10 NSHIPDATE DATE; 11 NSHIPENDDATE DATE; 12 NRVEDATE DATE; 13 NNAME VARCHAR2(55); 14 NADSS VARCHAR2(55) ; 15 NCIT VARCHAR2(55) ; 16 NLDSHIPPINGAMT NUMBER(38); 17 NSHIPPINGTYPE CHAR(35) ; 18 ACT CHAR(20); 19 20 begin 21 22 SELECT :NEW.SHIPPING_ID INTO NLSHIPID FROM DUAL; 23 SELECT :NEW.SHIPPER_ID INTO NSHIPPERID FROM DUAL; 24 SELECT :NEW.STATE_ID INTO NSTID FROM DUAL; 25 SELECT :NEW.RECEIPT_ID INTO NRPID FROM DUAL; 26 SELECT :NEW.SHIP_DATE INTO NSHIPDATE FROM DUAL; 27 SELECT :NEW.SHIP_ENDDATE INTO NSHIPENDDATE FROM DUAL; 28 SELECT :NEW.RECEIVE_DATE INTO NRVEDATE FROM DUAL; 29 SELECT :NEW.NAME INTO NNAME FROM DUAL; 30 SELECT :NEW.ADDRESS INTO NADSS FROM DUAL; 31 SELECT :NEW.CITY INTO NCIT FROM DUAL; 32 SELECT :NEW.SHIPPING_AMOUNT INTO NLDSHIPPINGAMT FROM DUAL; 33 SELECT :NEW.SHIPPING_TYPE INTO NSHIPPINGTYPE FROM DUAL; 34 SELECT 'Insert' INTO ACT From Dual; 35 36 37 insert into shipmentaudit 38 (SHIPPING_ID,SHIPPER_ID, STATE_ID, RECEIPT_ID, SHIP_DATE ,SHIP_ENDDATE, RECEIVE_DATE, 39 NAME, ADDRESS, CITY, SHIPPING_AMOUNT,SHIPPING_TYPE,Action_Type) 40 select NLSHIPID, NSHIPPERID, NSTID, NRPID, NSHIPDATE, NSHIPENDDATE,NRVEDATE,NNAME, NADSS, NCIT,NLDSHIPPINGAMT, 41 NSHIPPINGTYPE, ACT 42 from dual; 43 end shippmentAudit_inst_trigg; 44 / Trigger created. SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> create or replace trigger shippmentAudit_upt_trigg 2 after insert on shipment 3 for each row 4 DECLARE 5 6 NLSHIPID NUMBER(38); 7 NSHIPPERID NUMBER(38); 8 NSTID NUMBER(38);
  78. 78. 77 9 NRPID NUMBER(38); 10 NSHIPDATE DATE; 11 NSHIPENDDATE DATE; 12 NRVEDATE DATE; 13 NNAME VARCHAR2(55); 14 NADSS VARCHAR2(55) ; 15 NCIT VARCHAR2(55) ; 16 NLDSHIPPINGAMT NUMBER(38); 17 NSHIPPINGTYPE CHAR(35) ; 18 OLSHIPID NUMBER(38); 19 OSHIPPERID NUMBER(38); 20 OSTID NUMBER(38); 21 ORPID NUMBER(38); 22 OSHIPDATE DATE; 23 OSHIPENDDATE DATE; 24 ORVEDATE DATE; 25 ONAME VARCHAR2(55); 26 OADSS VARCHAR2(55) ; 27 OCIT VARCHAR2(55) ; 28 OLDSHIPPINGAMT NUMBER(38); 29 OSHIPPINGTYPE CHAR(35) ; 30 ACT CHAR(20); 31 32 begin 33 34 SELECT :NEW.SHIPPING_ID INTO NLSHIPID FROM DUAL; 35 SELECT :NEW.SHIPPER_ID INTO NSHIPPERID FROM DUAL; 36 SELECT :NEW.STATE_ID INTO NSTID FROM DUAL; 37 SELECT :NEW.RECEIPT_ID INTO NRPID FROM DUAL; 38 SELECT :NEW.SHIP_DATE INTO NSHIPDATE FROM DUAL; 39 SELECT :NEW.SHIP_ENDDATE INTO NSHIPENDDATE FROM DUAL; 40 SELECT :NEW.RECEIVE_DATE INTO NRVEDATE FROM DUAL; 41 SELECT :NEW.NAME INTO NNAME FROM DUAL; 42 SELECT :NEW.ADDRESS INTO NADSS FROM DUAL; 43 SELECT :NEW.CITY INTO NCIT FROM DUAL; 44 SELECT :NEW.SHIPPING_AMOUNT INTO NLDSHIPPINGAMT FROM DUAL; 45 SELECT :NEW.SHIPPING_TYPE INTO NSHIPPINGTYPE FROM DUAL; 46 47 SELECT :OLD.SHIPPING_ID INTO OLSHIPID FROM DUAL; 48 SELECT :OLD.SHIPPER_ID INTO OSHIPPERID FROM DUAL; 49 SELECT :OLD.STATE_ID INTO OSTID FROM DUAL; 50 SELECT :OLD.RECEIPT_ID INTO ORPID FROM DUAL; 51 SELECT :OLD.SHIP_DATE INTO OSHIPDATE FROM DUAL; 52 SELECT :OLD.SHIP_ENDDATE INTO OSHIPENDDATE FROM DUAL; 53 SELECT :OLD.RECEIVE_DATE INTO ORVEDATE FROM DUAL; 54 SELECT :OLD.NAME INTO ONAME FROM DUAL; 55 SELECT :OLD.ADDRESS INTO OADSS FROM DUAL; 56 SELECT :OLD.CITY INTO OCIT FROM DUAL; 57 SELECT :OLD.SHIPPING_AMOUNT INTO OLDSHIPPINGAMT FROM DUAL; 58 SELECT :OLD.SHIPPING_TYPE INTO OSHIPPINGTYPE FROM DUAL; 59 60 61 62 SELECT 'Update' INTO ACT From Dual; 63 64 65 insert into shipmentaudit
  79. 79. 78 66 (SHIPPING_ID,SHIPPER_ID, STATE_ID, RECEIPT_ID, SHIP_DATE ,SHIP_ENDDATE, RECEIVE_DATE, 67 NAME, ADDRESS, CITY, SHIPPING_AMOUNT,SHIPPING_TYPE,old_shippingid,old_shipperid, old_stateid, old_ReceiptID, 68 old_shipdate ,old_shipenddate, old_receivedate, 69 old_Name, old_Address, old_City, old_shippingamt,old_shippingtype, 70 Action_Type) 71 select NLSHIPID, NSHIPPERID, NSTID, NRPID, NSHIPDATE, NSHIPENDDATE,NRVEDATE,NNAME, NADSS, NCIT,NLDSHIPPINGAMT, 72 NSHIPPINGTYPE,OLSHIPID, OSHIPPERID, OSTID, ORPID, OSHIPDATE, OSHIPENDDATE,ORVEDATE,ONAME, OADSS, 73 OCIT,OLDSHIPPINGAMT,OSHIPPINGTYPE,ACT 74 from dual; 75 end shippmentAudit_upt_trigg; 76 / Trigger created. SQL> set echo off SQL> spool off;
  80. 80. 79 Database Altration
  81. 81. 80
  82. 82. 81
  83. 83. 82
  84. 84. 83
  85. 85. 84
  86. 86. 85 SQL> Alter table receipt 2 drop primary key; Table altered. SQL> Alter table receipt 2 drop constraint Receipt_Receiptid_uk cascade; Table altered. SQL> Alter table receipt drop column state_id; Table altered. SQL> Alter table receipt drop column payment_id; Table altered. SQL> Alter table receipt drop constraint Receipt_customerid_fk ; Table altered. SQL> Alter table receipt drop constraint Receipt_storeid_fk ; Table altered. SQL> Alter table receipt drop constraint Receipt_Productid_fk ; Table altered. SQL> SQL> SQL> SQL> SQL> Alter table receipt 2 modify receipt_finalamt constraint receipt_repfinamt_nn not null 3 modify receipt_amount constraint receipt_repamount_nn not null; Table altered. SQL> SQL> SQL> SQL> Alter table receipt 2 add constraint Receipt_Receipid_pk primary key(Receipt_ID,Employee_ID,Customer_ID,Store_ID 3 ,Product_ID); Table altered.
  87. 87. 86 SQL> Alter table receipt 2 drop constraint Receipt_Receipid_pk; Table altered. SQL> alter table receipt 2 add constraint receipt_receiptid_pk primary key(receipt_id, employee_id, customer_id, product_id, store_id); Table altered. SQL> SQL> alter table receipt 2 add constraint receipt_receiptid_uk unique (receipt_id); Table altered. SQL> SQL> SQL> SQL> alter table receipt 2 add constraint Receipt_customerid_fk foreign key(Customer_ID) references Customer(Customer_ID); Table altered. SQL> Alter table receipt 2 drop constraint Receipt_Employeeid_fk; Table altered. SQL> alter table receipt 2 add constraint Receipt_Employeeid_fk foreign key(Employee_ID) references Employee (Employee_ID); Table altered. SQL> alter table receipt 2 add constraint Receipt_storeid_fk foreign key(Store_id) references store(Store_id); Table altered. SQL> SQL> alter table receipt 2 add constraint Receipt_Productid_fk foreign key(Product_ID) references Product (Product_ID); Table altered. SQL> SQL> alter table receipt drop constraint receipt_repfinamt_nn; Table altered.
  88. 88. 87 SQL> alter table receipt drop constraint receipt_ReceiptTax_nn; Table altered. SQL> commit; Commit complete. SQL> alter table receiptaudit drop column state_id; Table altered. SQL> alter table receiptaudit drop column old_stateid; Table altered. SQL> alter table receiptaudit drop column old_paymentid; Table altered. SQL> alter table receiptaudit drop column payment_id; Table altered. SQL> ALTER TABLE PAYMENTCOP 2 ADD RECEIPT_ID INTEGER; Table altered. SQL> ALTER TABLE PAYMENTCOP 2 ADD Authorized_Amt decimal(8,2); Table altered. SQL> Alter table PaymentCop 2 modify payment_createddate constraint paymentcop_createdate_nn not null 3 modify payment_status constraint paymentcop_paymentstatus_nn not null 4 modify payment_expdate constraint paymentcop_payexpdate_nn not null; Table altered. SQL> Alter table PAYMENTCOP 2 drop constraint PaymentCop_paymentid_pk; Table altered. SQL> ALTER TABLE PAYMENTCOP 2 ADD CONSTRAINT PAYMENTCOP_PAYMENTID_PK PRIMARY KEY(PAYMENT_ID, RECEIPT_ID);
  89. 89. 88 Table altered. SQL> ALTER TABLE PAYMENTCOP 2 ADD CONSTRAINT PAYMENTCOP_PAYMENTID_UK UNIQUE(PAYMENT_ID); Table altered. SQL> ALTER TABLE PAYMENTCOP 2 ADD CONSTRAINT PAYMENTCOP_RECEIPTID_FK FOREIGN KEY(RECEIPT_ID) REFERENCES RECEIPT(RECEIPT_ID); Table altered. SQL> Alter table PaymentCop 2 modify Authorized_Amt constraint paymentcop_authorizedamt_nn not null; Table altered. SQL> alter table paymentcopaudit add receipt_id integer 2 ; Table altered. SQL> alter table paymentcopaudit add old_receiptid integer; Table altered. SQL> alter table paymentcopaudit add authorized_amt decimal(8,2); Table altered. SQL> alter table paymentcopaudit add Old_AuthorizedAmt decimal(8,2); Table altered. SQL> commit; Commit complete. SQL> drop table shipment; SQL> create table shipment 2 (shipping_id integer GENERATED ALWAYS AS IDENTITY 3 (START WITH 0235 INCREMENT BY 26), 4 shipper_id integer , 5 state_id integer , 6 Receipt_ID integer , 7 ship_date date, 8 ship_enddate date, 9 receive_date date,
  90. 90. 89 10 Name varchar2(55), 11 Address varchar2(55), 12 City varchar2(55), 13 shipping_amount numeric, 14 shipping_type char(35), 15 constraint shipment_shipmentid_pk primary key(shipping_id,shipper_id,RECEIPT_ID ), 16 constraint shipment_shipermid_uk unique (shipping_id), 17 constraint shipment_shipperid_fk foreign key(shipper_id) references shippingco(shipper_id), 18 CONSTRAINT SHIPMENT_RECEIPTID_FK FOREIGN KEY(RECEIPT_ID) REFERENCES RECEIPT(RECEIPT_ID) 19 ); Table created. SQL> SQL> alter table shipment 2 modify Name constraint shipment_shipname_nn not null 3 modify Address constraint shipment_address_nn not null 4 modify city constraint shipment_city_nn not null 5 modify shipping_amount constraint shipment_shipamount_nn not null 6 modify shipping_type constraint shipment_shippingtype_nn not null; Table altered. SQL> spool off; SQL> CREATE OR REPLACE TRIGGER ManagementAuditt_del_trigg 2 AFTER DELETE ON Management 3 for each row 4 DECLARE 5 OMID Integer; 6 OEMP Integer; 7 OHD DATE; 8 OEND DATE; 9 OSTID integer; 10 ACT char(20); 11 BEGIN 12 13 SELECT :OLD.Manager_ID INTO OMID FROM DUAL; 14 SELECT :OLD.Employee_ID INTO OEMP FROM DUAL; 15 SELECT :OLD.Hire_Date INTO OHD FROM DUAL; 16 SELECT :OLD.Hire_EndDate INTO OEND FROM DUAL; 17 SELECT 'Delete' INTO ACT FROM DUAL; 18 SELECT :OLD.STORE_ID INTO OSTID FROM DUAL; 19 20 INSERT INTO ManagementAudit(Old_ManagerID,Old_EmployeeID ,Old_HireDate, Old_HireEndDate ,Action_Type, old_storeid) 21 SELECT OMID, OEMP, OHD,OEND,ACT, OSTID 22 FROM DUAL; 23 24 25 end ManagementAuditt_del_trigg; 26 /
  91. 91. 90 Trigger created. SQL> CREATE OR REPLACE TRIGGER ManagementAuditt_inst_trigg 2 AFTER INSERT ON Management 3 for each row 4 DECLARE 5 NMID Integer; 6 NEMP Integer; 7 NHD DATE; 8 NEND DATE; 9 ACT char(20); 10 NTSID Integer; 11 BEGIN 12 13 SELECT :NEW.Manager_ID INTO NMID FROM DUAL; 14 SELECT :NEW.Employee_ID INTO NEMP FROM DUAL; 15 SELECT :NEW.Hire_Date INTO NHD FROM DUAL; 16 SELECT :NEW.Hire_EndDate INTO NEND FROM DUAL; 17 SELECT 'Insert' INTO ACT FROM DUAL; 18 SELECT :NEW.STORE_ID INTO NTSID from DUAL; 19 20 INSERT INTO ManagementAudit(Manager_ID,Employee_ID ,Hire_Date, Hire_EndDate ,Action_Type, Store_ID) 21 SELECT NMID, NEMP, NHD,NEND,ACT, NTSID FROM DUAL; 22 23 24 end ManagementAuditt_inst_trigg; 25 / Trigger created. SQL> SQL> CREATE OR REPLACE TRIGGER ManagementAuditt_updt_trigg 2 AFTER UPDATE ON Management 3 for each row 4 DECLARE 5 NMID Integer; 6 NEMP Integer; 7 NHD DATE; 8 NEND DATE; 9 OMID Integer; 10 OEMP Integer; 11 OHD DATE; 12 OEND DATE; 13 ACT char(20); 14 OSTID integer; 15 NTSID Integer; 16 BEGIN 17 18 SELECT :NEW.Manager_ID INTO NMID FROM DUAL; 19 SELECT :NEW.Employee_ID INTO NEMP FROM DUAL; 20 SELECT :NEW.Hire_Date INTO NHD FROM DUAL; 21 SELECT :NEW.Hire_EndDate INTO NEND FROM DUAL; 22 SELECT :OLD.Manager_ID INTO OMID FROM DUAL; 23 SELECT :OLD.Employee_ID INTO OEMP FROM DUAL; 24 SELECT :OLD.Hire_Date INTO OHD FROM DUAL;

×