Your SlideShare is downloading. ×
ERETAILORACLE DATABASE
SECURITY PROJECT
DBST Security
UMUC SPRING 2012
By
Sunny Okoro

1
Table of Contents
ANALYSIS ..................................................................................................
APPLICATION CONTEXT .........................................................................................................
ANALYSIS

4
BUSINESS REQUIREMENTS
ERETAIL a Pacific Northwest based electronic retail store founded in 1995 as a regular neighborhood ...
SYSTEM PROPOSAL
DataInc Solution a Washington D.C basedcompany proposed an oracle solution for ERetail that would be used ...
customer identification numbers to any customers or from the public. Currently ERETAIL uses
the same customer identificati...
ENTITY RELATION DIAGRAM

8
9
DESIGN

10
DATABASE CREATION

Table and Objects Creation
/* creates table employee to hold all employee data */
create table EMPLOYEE...
/*Adds the foreign key and not null constraints the employee table */
Alter table employee
add constraint emp_custid_fk fo...
'
select EMPNATIONALID_SEQ.nextval into :NEW."NATIONAL_ID" from dual; '||
' end if; '||
' end if; '||
'end;';
end;
/
/* cr...
/*Adds the not null constraint to the columns */

Alter table customer
modify(first_name constraint cust_firstname_nn not ...
modify(department_id constraint dept_departid_nn not null )
modify(name constraint dept_name_nn not null);
CREATE PUBLIC S...
Office_Phone varchar2(35),
CONSTRAINT HRREC_EMPHRID_PK PRIMARY KEY(EMPLOYEE_ID, HR_ID, DEPARTMENT_ID),
CONSTRAINT HRREC_EM...
Create table product
(Product_ID Number constraint prod_prodnumber_nn not null,
product_Name varchar2(90),
Product_Price n...
Create or replace sequence creditcard start with 1200007800002345 increment by 809 nocycle nocache order;
begin
execute im...
, constraint sales_custid_fk foreign key(customer_id) references customer(customer_id) on delete cascade,
constraint sales...
close_date number,
notes clob,
constraint custclcad_pk primary key(serial_number,Account_Number),
constraint custclcad_ser...
' end if; '||
'end;';
END;
/

/*creates the project work book table to hold all important information relating to a projec...
'
select PJWBK_WBID_SEQ.nextval into :NEW."WORKBOOK_ID" from dual; '||
' end if; '||
' end if; '||
'end;';
end;
/

/*creat...
' if :NEW."INVENTORY_ID" is null then '||
'
select INVENTORY_INVID_SEQ.nextval into :NEW."INVENTORY_ID" from dual; '||
' e...
ALTER TABLE HRRECORD
MODIFY RANK VARCHAR2(45);
ALTER TABLE DEPARTMENT
MODIFY NAME VARCHAR2(40);
ALTER TABLE CUSTOMERCARDS
...
ALTER TABLE CUSTOMERCARDSCLOSE
MODIFY ACCOUNT_NUMBER CHAR(45);
ALTER TABLE CUSTOMERCARDSCLOSE
MODIFY CLOSE_DATE DATE;
RENA...
TABLE POPULATION

Insert statements for each of the tables. Please open them individually.

EMPLOYEE_INSERTS.sql

CUSTOMER...
create user BrendaUDH
identified by BrenDJK
password expire;

create user BerryHK
identified by joeberr
password expire;
c...
identified by Georgehgy
password expire;
create user MichaelsThVY
Identified by ThomasMichel
password expire;

create user...
create user ThierrydherLK
identified by dhersthier
password expire;
create user PhilipsCLZ
identified by Carolphilp
passwo...
/* creates the sequence to populate the primary key columns with a trigger defined below */
create sequence auth_authid_se...
INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME)
values( 87 ,'AckermanJKP');
INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID...
APPLICATION CONTEXT
Employee
Allows employee users to view their own records when they query certain table they have acces...
INTO l_EMPID FROM UEMP
WHERE username = SYS_CONTEXT('USERENV', 'SESSION_USER');
DBMS_SESSION.SET_CONTEXT
(namespace => 'EM...
PASSWORD MANAGEMENT
Password Authentication
--------------------------Password Authentication----------------------------
...
IF (p_password is NULL)
THEN
---PASSWORD IS EITHER PASSED AS PARAMETER OR SET SET USER'S NAME---l_password :=rec.username;...
Password requirement ensures that a user password meets the requirements established by the organization

----------------...
-- MAKE SURE PASSWORD IS NOT MADE UP OF NUMBERS ----IF(regexp_like(p_new_password, '[:alnum:]' ) = FALSE)
THEN
L_RETURN_VA...
AUDIT MANAGEMENT
Ensures that database activities both by external and internal users are audited for recording purpose to...
DBMS_OUTPUT.put_line('priv_used: '
|| rec.priv_used);
DBMS_OUTPUT.put_line('comments: '
|| rec.comment_text);
DBMS_OUTPUT....
DBMS_OUTPUT.put_line('HOW:
'
|| rec.sql_text);
DBMS_OUTPUT.put_line
('--------------------End Of Record-------------------...
VIRTUAL PRIVATE DATABASE
/*Creates the function to retrieve the employee id */

/*Allows employee to view the projects the...
RETURN VARCHAR2
AS
BEGIN
RETURN 'EMPID = SYS_CONTEXT (''EMPLOYE_SEC'',''EMPID'')';
END;
/
/*Allows employee to view all th...
SELECT FIRST_NAME, MIDDLE_NAME, LAST_NAME, BIRTH_DATE, GENDER, EMPLOYEE_ID,
MARITAL_STATUS, ADDRESS, CITY, STATE, POSTAL_C...
D.NAME,
G.FIRST_NAME||','||G.LAST_NAME AS "MANAGER_NAME"
FROM
EMPLOYEE E
INNER JOIN HRRECORD H
ON E.EMPLOYEE_ID = H.EMPLOY...
NON-DYNAMIC VIEW

/*Creates view used by customer representatives to query the database based on Account Card provided by ...
ON H.DEPARTMENT_ID = D.DEPARTMENT_ID
INNER JOIN EMPLOYEE G
ON
G.EMPLOYEE_ID = D.MANAGER_ID
ORDER BY D.DEPARTMENT_ID;
/*cre...
CREATE VIEW DEPARTMENTS
AS
SELECT E.FIRST_NAME ||','|| E.LAST_NAME AS MANAGER, D.NAME,
H.OFFICE_PHONE
FROM EMPLOYEE E
INNE...
AS
SELECT c.customer_Id, C.CITY, C.STATE, C.BIRTH_DATE, C.POSTAL_CODE, C.COUNTRY, C.GENDER,
C.YEARLY_INCOME,
C.MARITAL_STA...
GRANT CREATE SESSION TO IvoLKW;
GRANT CREATE SESSION TO kaneVMP;
GRANT CREATE SESSION TO ThierrydherLK;
GRANT CREATE SESSI...
/*RANALYST*/
CREATE ROLE RANALYST;
CREATE OR REPLACE PUBLIC SYNONYM CUSTDATA02 FOR rCUSTOMERDATA ;
GRANT SELECT ON CUSTDAT...
CREATE ROLE CUSTOMERREP;
CREATE OR REPLACE PUBLIC SYNONYM CUSTINFO FOR CUSTOMERINFO;
GRANT SELECT, INSERT, UPDATE ON CUSTI...
GRANT EMPLOYEE TO RaymondPLK;
GRANT EMPLOYEE TO AckermanJKP;
GRANT EMPLOYEE TO RounthwaiteUHG;
GRANT EMPLOYEE TO MichaelsT...
CREATE OR REPLACE PUBLIC SYNONYM CustCard for customercards;
CREATE OR REPLACE public SYNONYM CARDCLOSE FOR customercardsc...
IMPLEMENNTATION

54
DATABASE CREATION

/************************** Spool files of table, synonym, triggers and sequence creations ************...
9
10
11
12

modify(state constraint empl_state_nn not null)
modify(postal_code constraint empl_postalcode_nn not null)
mod...
12
13
14
15
16
17
18
19
20

profession varchar2(34),
Address Varchar2(50),
City Varchar2(20),
State char(35),
Postal_Code ...
6
CONSTRAINT DEPTART_MANGID_FK FOREIGN KEY(MANAGER_ID) REFERENCES
EMPLOYEE(EMPLOYEE_ID)
7
);
Table created.
SQL>
SQL> /* c...
5 SICK_HOURS NUMBER,
6 VACATION_HOURS NUMBER,
7 RANK CHAR(30),
8 HIRE_DATE DATE,
9 PAY_RATE NUMBER,
10 Office_Phone varcha...
SQL>
SQL>
2
3
4
5
6
7
8

Create table product
(Product_ID Number constraint prod_prodnumber_nn not null,
product_Name varc...
create sequence succeeded.
begin
execute immediate 'create or replace trigger ccredit '||
'
before insert on "SYSTEM"."TRA...
SQL> Alter table sales
2 add constraint saltransidU_fk foreign key (Transacton_ID) references
transactions(Transacton_ID);...
constraint project_proj_pk primary key (project_id, manager_id),
constraint project_magid_fk foreign key(manager_id) refer...
create sequence succeeded.

begin
execute immediate 'create or replace trigger pjworkbook '||
'
before insert on "SYSTEM"....
'
if inserting then '||
'
if :NEW."INVENTORY_ID" is null then '||
'
select INVENTORY_INVID_SEQ.nextval into :NEW."INVENTOR...
Sales Insert Statement

SAL_FN.SQL

Department Insert Statement

DEPARTMENT.SQL

Hrrecord Insert Statement

HR_FN.SQL

Pro...
3

password expire;

User created.
SQL>
SQL> create user BerryHK
2 identified by joeberr
3 password expire;
User created.
...
User created.
SQL>
SQL> create user LiGeorgeTRW
2 identified by Georgehgy
3 password expire;
User created.
SQL>
SQL>
SQL>
...
SQL>
SQL> create user IvoLKW
2 identified by Salmreivo
3 password expire;
User created.
SQL>
SQL> create user kaneVMP
2 id...
SQL>
SQL> /*creates authentication table*/
SQL>
SQL> create table authenticationEMP
2 (EMPLOYEE_ID NUMBER,
3
AUTHENTICATIO...
1 row created.
SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID, USER_NAME)
2
values(214,'BrendaUDH');
1 row created.
SQL> I...
2

values( 198 ,

'MichaelsThVY');

1 row created.
SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME)
2
values( 268...
1 row created.
SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME)
2
values( 17 , 'fordjeffNK');
1 row created.
SQL>...
l_EMPID NUMBER;
BEGIN
SELECT EMPID
INTO l_EMPID FROM UEMP
WHERE username = SYS_CONTEXT('USERENV', 'SESSION_USER');
DBMS_SE...
/*creates the index for username and the verifier*/
create index verifier

on pwordauthenticate(username, verifier)

creat...
--- RETURN TRUE IF PASSWORD IS STRONG ENOUGH----RETURN BOOLEAN
AS
l_return_val BOOLEAN := TRUE;
BEGIN
---CHECK TO BE SURE ...
---KEEPS TRACK OF USERS WHO ACCESSED THE DATABASE-----------BEGIN
for rec IN
(SELECT username, action_name,
TO_CHAR(TIMEST...
anonymous block completed

/* Audit was created after the views has been created*/
AUDIT
AUDIT
AUDIT
AUDIT
AUDIT
AUDIT
AUD...
SQL>
SQL>
SQL>
2
3
4
5
6
7
8
9

CREATE OR REPLACE FUNCTION EMPID_RET(
p_schema IN VARCHAR2 DEFAULT NULL,
p_object IN VARCH...
(-20001,
CHR(10)
|| '** YOU CAN ONLY UPDATE YOUR OWN RECORD.'
|| CHR(10)
||'** YOUR EMPLOYEE ID IS'
|| SYS_CONTEXT ('EMPLO...
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

SELECT
E.FIRST_NAME ||'-'||E.MIDDLE_NAME||','|| E.LAST_NAME AS EMPLOYEE, H.RANK,
D....
8
9
10
11
12

SQL>
SQL>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

E.EMPLOYEE_ID = D.MANAGER_ID
INNER JOIN
HR...
view RCUSTOMERDATA created.
View created.
SQL> set echo off
SQL> spool off;

DATABASE MANAGEMENT
> GRANT CREATE SESSION
GR...
GRANT succeeded.
> GRANT CREATE SESSION TO fordjeffNK
GRANT succeeded.
> GRANT CREATE SESSION TO STADICKDL
GRANT succeeded...
> CREATE ROLE SALES
role SALES created.
> GRANT SELECT ON TRANSACTIONS TO SALES
GRANT succeeded.
> GRANT SELECT ON SALES T...
> GRANT EMPLOYEE TO DavidMGI
GRANT succeeded.
> GRANT EMPLOYEE TO EricYMU
GRANT succeeded.
> GRANT EMPLOYEE To Samarawickr...
grant select on invtuser to sales;
GRANT succeeded.
GRANT succeeded.
> show errors
No Errors.

> GRANT CREATE SESSION
GRAN...
> GRANT CREATE SESSION TO STADICKDL
GRANT succeeded.
> GRANT CREATE SESSION TO DAVYALOVSKY0
GRANT succeeded.
> show errors...
QUALITY ASSURANCE

89
DATABASE DIAGRAM

90
DATABASE DICTIONARY
SELECT TABLE_NAME, CONSTRAINT_NAME, CONSTRAINT_TYPE, DELETE_RULE,STATUS, INDEX_NAME
FROM USER_CONSTRAI...
EMPL_STATE_NN
EMPL_CITY_NN
EMPL_ADDRESS_NN
EMPL_GENDER_NN
EMPL_LASTNAME_NN
EMPL_BIRTHDATE_NN
EMPL_MIDNAME_NN
EMPL_FNAME_NN...
EMPLOYEE
NO

SYSTEM

EMPDIRECTORY

SYSTEM

SELECT

SYSTEM

EMPLOYEERV

SYSTEM

UPDATE

SYSTEM

EMPLOYEEHR

SYSTEM

UPDATE
...
ACCOUNT_NUMBER NOT NULL CHAR(45)
CUSTOMER_ID
NOT NULL NUMBER
PRINT_DATE
DATE
STATUS
CHAR(20)
EMPLOYEE_ID
NOT NULL NUMBER
D...
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
Upcoming SlideShare
Loading in...5
×

DB Security Oracle 11g-Application Context, Dynamic Views & Aduits

1,063

Published on

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

  • Be the first to like this

No Downloads
Views
Total Views
1,063
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "DB Security Oracle 11g-Application Context, Dynamic Views & Aduits"

  1. 1. ERETAILORACLE DATABASE SECURITY PROJECT DBST Security UMUC SPRING 2012 By Sunny Okoro 1
  2. 2. Table of Contents ANALYSIS ............................................................................................................................................................................................ 4 BUNINESES REQUIREMENT ............................................................................................................................................................. 5 SYSTEM PROPOSAL .................................................................................................................................................................... 6 ENTITY RELATION DIAGRAM ....................................................................................................................................................... 8 DESIGN .............................................................................................................................................................................................. 10 DATABASE CREATION ................................................................................................................................................................... 11 TABLE POPULATION .......................................................................................................................................................................... 26 USER MANAGEMENT.................................................................................................................................................................... 26 APPLICATION CONTEXT ................................................................................................................................................................ 32 PASSWORD MANAGEMENT ........................................................................................................................................................ 34 AUDIT MANAGEMENT ................................................................................................................................................................. 38 VIRTUAL PRIVATE DATABAE ......................................................................................................................................................... 41 DYNAMIC VIEWS .......................................................................................................................................................................... 42 NON DUNAMIC VIEWS ................................................................................................................................................................. 45 DATABASE MANAGEMENT .......................................................................................................................................................... 48 IMPLMENTATION ............................................................................................................................................................................. 54 DATABASE CREATION ................................................................................................................................................................... 55 TABLE POPULATION .......................................................................................................................................................................... 65 USER MANAGEMENT.................................................................................................................................................................... 66 2
  3. 3. APPLICATION CONTEXT ................................................................................................................................................................ 66 PASSWORD MANAGEMENT ........................................................................................................................................................ 67 ADUIT MANAGEMENT................................................................................................................................................................. 67 VIRTUAL PRIVATE DATABAE ............................................................................................................................................................. 67 DYNAMIC VIEWS .......................................................................................................................................................................... 67 NON DUNAMIC VIEWS ................................................................................................................................................................. 67 DATABASE MANAGEMENT .......................................................................................................................................................... 68 QULATITY ASSURANCE .................................................................................................................................................................... 69 DATABASE DIAGRAM ................................................................................................................................................................... 70 DATABASE DICTIONARY .................................................................................................................................................................. 72 DATA VALIDATION ..................................................................................................................................................................... 76 DATA SECURITY ............................................................................................................................................................................... 77 AUDIT MANAGEMENT ................................................................................................................................................................. 93 3
  4. 4. ANALYSIS 4
  5. 5. BUSINESS REQUIREMENTS ERETAIL a Pacific Northwest based electronic retail store founded in 1995 as a regular neighborhood store needs a database system to support their ecommerce system that was launched in 2000 and other daily activities. The database system shall meet the following requirements. 1. The database shall process multiplesessions without causing connection problems. 2. The database shall allow employees to view their own employee records and human resources files 3. The database shall have a password requirement to prevent authorized access that could be caused by weak passwords. 4. The database shall allow employees to view their own records 5. To maintain data integrity no delete operation would be allowed in the database. 6. The database shall allow ERETAIL to manage its inventory and various projects. 5
  6. 6. SYSTEM PROPOSAL DataInc Solution a Washington D.C basedcompany proposed an oracle solution for ERetail that would be used to manage daily operations. The Oracle 11g database would be integrated with existing applications to retrieve and process data. 1. Application context would be used to allow customers and employees to view their own records. A trigger would be created on the underlying table to restrict data being updated or deleted to that of the user based on the application context definition. 2. A password profile and authentication validating rules would be used to validate each password based on established requirements. 3. An audit management would be implemented to audit each user’s behaviors and actions in the database. 4. Employees are given access to data based on the roles they are identified by within the organization. 5. To enhance security, a new customer card system is introduced to replace the one way customer id schema. When a user calls in for assistance, they would be asked for their account number instead of a customer identification number as in the current system. The customer representative would query the database and ask the customer toconfirm their identity. Having a customer card system would prevent the organization from disclosing the 6
  7. 7. customer identification numbers to any customers or from the public. Currently ERETAIL uses the same customer identification number given to customer to query internal database systems. A criminal who knows the customer identifications of individual customers can easily break into the system by providing the employee credentials in a query. The account system would eliminate that need. 6. Customer personal identifiers like address, birthdate and phone would be removed from views that are being utilized by employees whose role(s) does not require them to use for their assignments. 7. Inventory, customer cards and customer cards close tables would contain employee identification numbers to make it easier to know which employee issued a customer card or close the account and which employee updated the inventory table. 8. The Employee identification number is a public number departmental managers and project management team to identify the employee. Only the HR_ID isused for to access secure systems like payroll system which would prompt them to enter it along with their username. This would replace the use of employee identification number to access sensitive information. 9. Only the database administrator is allowed to create database objects and management of those objects. 7
  8. 8. ENTITY RELATION DIAGRAM 8
  9. 9. 9
  10. 10. DESIGN 10
  11. 11. DATABASE CREATION Table and Objects Creation /* creates table employee to hold all employee data */ create table EMPLOYEE (Employee_ID Number constraint employeeid_pk primary key, First_Name Varchar2(30), Middle_Name Varchar2(30), Last_Name Varchar2(30), Birth_Date varchar2(45), Gender Char(15), Marital_status Char(20), Address Varchar2(50), City Varchar2(35), State varchar(35), Postal_Code varchar2(20), Phone Varchar2(25), National_ID NUMBER ); /* Adds the customer column to the employee table*/ Alter table employee add customer_id number; 11
  12. 12. /*Adds the foreign key and not null constraints the employee table */ Alter table employee add constraint emp_custid_fk foreign key(customer_id) references customer(customer_id); Alter table employee modify(first_name constraint empl_fname_nn not null) modify(middle_name constraint empl_midname_nn not null) modify(last_name constraint empl_lastname_nn not null) modify(birth_date constraint empl_birthdate_nn not null) modify(gender constraint empl_gender_nn not null) modify(address constraint empl_address_nn not null) modify(city constraint empl_city_nn not null) modify(state constraint empl_state_nn not null) modify(postal_code constraint empl_postalcode_nn not null) modify(National_id constraint empl_nationalid_nn not null) modify(phone constraint empl_phone_nn not null); /* creates the sequence used to create the unique numbers for the national id column*/ CREATE SEQUENCE EMPNATIONALID_SEQ INCREMENT BY 120 start with 018892343 nocache nocycle order; /* creates the trigger to automatically populate the national id column */ begin execute immediate 'create or replace trigger nationalid '|| ' before insert on "SYSTEM"."EMPLOYEE" '|| ' for each row '|| 'begin '|| ' if inserting then '|| ' if :NEW."NATIONAL_ID" is null then '|| 12
  13. 13. ' select EMPNATIONALID_SEQ.nextval into :NEW."NATIONAL_ID" from dual; '|| ' end if; '|| ' end if; '|| 'end;'; end; / /* creates the public snyonym for employee*/ create public synonym employee for employee; /*creates the table customer*/ create table customer (Customer_ID number constraint custo_custid_pk primary key, First_Name Varchar2(35), Middle_Name Varchar2(35), Last_Name Varchar2(35), Gender Char(15), Birth_Date Varchar2(45), Yearly_Income Number, Total_Childreen Number, Total_Cars_Owned Number, Marital_Status Varchar2(35), profession varchar2(34), Address Varchar2(50), City Varchar2(20), State char(35), Postal_Code varchar2(20), country varchar2(35), Phone Varchar2(25), Educational_Background varchar2(35) ); 13
  14. 14. /*Adds the not null constraint to the columns */ Alter table customer modify(first_name constraint cust_firstname_nn not null) modify(middle_name constraint cust_midname_nn not null) modify(last_name constraint cust_lastname_nn not null) modify(birth_date constraint cust_birthdate_nn not null) modify(gender constraint cust_gender_nn not null) modify(address constraint cust_address_nn not null) modify(city constraint cust_city_nn not null) modify(state constraint cust_state_nn not null) modify(postal_code constraint cust_postalcode_nn not null) modify(phone constraint cust__phone_nn not null); /* creates the public synonym for customer */ create public synonym customer for customer; /* creates the department table*/ CREATE TABLE DEPARTMENT (DEPARTMENT_ID NUMBER, NAME VARCHAR(20), MANAGER_ID NUMBER, CONSTRAINT DEPART_DEPARTSTRID_PK PRIMARY KEY(DEPARTMENT_ID), CONSTRAINT DEPTART_MANGID_FK FOREIGN KEY(MANAGER_ID) REFERENCES EMPLOYEE(EMPLOYEE_ID) ); /* creates the not null constraint to the department table */ Alter table Department 14
  15. 15. modify(department_id constraint dept_departid_nn not null ) modify(name constraint dept_name_nn not null); CREATE PUBLIC SYNONYM DEPARTMENT FOR DEPARTMENT; /* create the sequence for the department id column and the trigger to automatically populate it*/ CREATE SEQUENCE depart_deptid_seq increment by 89 start with 208 NOCYCLE nocache order; begin execute immediate 'create or replace trigger deptid_trgg '|| ' before insert on "SYSTEM"."DEPARTMENT" '|| ' for each row '|| 'begin '|| ' if inserting then '|| ' if :NEW."DEPARTMENT_ID" is null then '|| ' select DEPART_DEPTID_SEQ.nextval into :NEW."DEPARTMENT_ID" from dual; '|| ' end if; '|| ' end if; '|| 'end;'; end; / /* creates the HRRECORD table to hold all the employee data */ CREATE TABLE HRRECORD (EMPLOYEE_ID NUMBER, HR_ID NUMBER, DEPARTMENT_ID NUMBER, SICK_HOURS NUMBER, VACATION_HOURS NUMBER, RANK CHAR(30), HIRE_DATE DATE, PAY_RATE NUMBER, 15
  16. 16. Office_Phone varchar2(35), CONSTRAINT HRREC_EMPHRID_PK PRIMARY KEY(EMPLOYEE_ID, HR_ID, DEPARTMENT_ID), CONSTRAINT HRREC_EMPHIRIDUK_UK UNIQUE (HR_ID), CONSTRAINT HRREC_HRDEPTID_FK FOREIGN KEY(DEPARTMENT_ID)REFERENCES DEPARTMENT(DEPARTMENT_ID) ON DELETE CASCADE, CONSTRAINT HRREC_EMPLOYEEID_FK FOREIGN KEY(EMPLOYEE_ID) REFERENCES EMPLOYEE (EMPLOYEE_ID) ON DELETE CASCADE ); CREATE PUBLIC SYNONYM HRRECORD FOR HRRECORD; /* creates the sequences to create primary key values and the trigger to generate them automatically*/ CREATE SEQUENCE HR_HRID_SEQ increment by 887977 start with 268 NOCYCLE nocache order; begin execute immediate 'create or replace trigger hrrid2_trgg '|| ' before insert on "SYSTEM"."HRRECORD" '|| ' for each row '|| 'begin '|| ' if inserting then '|| ' if :NEW."HR_ID" is null then '|| ' select HR_HRID_SEQ.nextval into :NEW."HR_ID" from dual; '|| ' end if; '|| ' end if; '|| 'end;'; end; / /* creates the table product to hold all data relating to a product*/ 16
  17. 17. Create table product (Product_ID Number constraint prod_prodnumber_nn not null, product_Name varchar2(90), Product_Price number, Product_Brand Varchar2(35), Product_Description CLOB, Product_Category varchar2(30) ); /* creates the not null and primary key constraint */ Alter table product modify(Product_Price constraint prod_prodcost_nn not null) modify(product_name constraint prod_prodname_nn not null) modify(Product_Category constraint prod_prodcategory_nn not null); Alter table product modify(product_id constraint prod_productid_pk primary key); /*creates the tansactions table */ create table transactions (Transacton_ID VARCHAR2(60), Credit_Card_ID Number, Card_Type char(24), EXP_DATE DATE, Trans_Date Date, Amount_Charged Number, Brand Char(20), Constraint trans_transactionsid_pk PRIMARY KEY (Transacton_ID) ); /*creates the sequece used to populate the credit card values */ 17
  18. 18. Create or replace sequence creditcard start with 1200007800002345 increment by 809 nocycle nocache order; begin execute immediate 'create or replace trigger ccredit '|| ' before insert on "SYSTEM"."TRANSACTIONS" '|| ' for each row '|| 'begin '|| ' if inserting then '|| ' if :NEW."CREDIT_CARD_ID" is null then '|| ' select CREDITCARD.nextval into :NEW."CREDIT_CARD_ID" from dual; '|| ' end if; '|| ' end if; '|| 'end;'; end; / /*Create the sales table */ create table sales (Customer_id number, Transacton_ID VARCHAR2(60), Product_id number, Order_ID Number, QTY_Ordered number, Product_Price_Original number, Product_price_WT_QTY number, Tax_Amount_Charged Number, Freight_Amount_charged number, Total_Amount Number, Order_Date Date, Constraint sales_custprodidtrand_pk primary key(customer_id, product_id, Transacton_ID, order_id) , constraint sales_salid_uk unique(Order_id) 18
  19. 19. , constraint sales_custid_fk foreign key(customer_id) references customer(customer_id) on delete cascade, constraint sales_pproductid_fk foreign key(product_id) references product(product_id) on delete cascade ); /* adds the foreign key constraint linking transaction to sales table */ Alter table sales add constraint saltransidU_fk foreign key (Transacton_ID) references transactions(Transacton_ID); /*creates table to hold all customer card information*/ create table customercards (Account_Number Number, customer_id Number, print_date date, print_employee_id number, status char(20), employee_id number, constraint custcard_empid_fk foreign key(print_employee_id) references employee(employee_id), constraint custcards_pk primary key (Account_Number,Customer_id, employee_Id), constraint custcards_custid_fk foreign key (customer_id) references customer(customer_id), constraint custcards_empid_fk foreign key(employee_id) references employee(employee_id), constraint custcard_ser_uk unique(Account_Number) ); /*creates the table to hold all cards closed or lost reported by customer*/ create table customercardsclose (serial_number number, Account_Number number, close_employee_ID number, 19
  20. 20. close_date number, notes clob, constraint custclcad_pk primary key(serial_number,Account_Number), constraint custclcad_sernum_uk unique (serial_number), constraint custclad_cempid_fk foreign key(close_employee_ID) references employee(employee_id) ); /*creates the table to hold all projects the company are working or has worked on*/ create table projects (project_id number, Manager_id Number, project_title number, start_date date, end_date date, Awarded_Amount number, notes clob, constraint project_proj_pk primary key (project_id, manager_id), constraint project_magid_fk foreign key(manager_id) references employee(employee_id), constraint project_projid_uk unique (project_id) ); /*creates the sequence to populate the peoject_id column of projects and the trigger to fire automatic inserts*/ create sequence projet_projeid_sq start with 054456 order nocycle nocache increment by 56; begin execute immediate 'create or replace trigger project_trgg '|| ' before insert on "SYSTEM"."PROJECTS" '|| ' for each row '|| 'begin '|| ' if inserting then '|| ' if :NEW."PROJECT_ID" is null then '|| ' select PROJET_PROJEID_SQ.nextval into :NEW."PROJECT_ID" from dual; '|| ' end if; '|| 20
  21. 21. ' end if; '|| 'end;'; END; / /*creates the project work book table to hold all important information relating to a project*/ create table Projectworkbook (project_id number, employee_id number, workbook_id number, Hours_Assign Number, Role varchar2(40), constraint projwork_pk primary key(employee_id, project_id, workbook_id), constraint projwork_wbk_uk unique (workbook_id), constraint projwork_wb_fk foreign key(project_id) references projects(project_id), constraint projwork_emp_id_fk foreign key(employee_id) references employee(employee_id) ); /*creates the sequence and trigger to fire inserts for pk column*/ create sequence pjwbk_wbid_seq start with 06745 increment by 34 nocycle order nocache; begin execute immediate 'create or replace trigger pjworkbook '|| ' before insert on "SYSTEM"."PROJECTWORKBOOK" '|| ' for each row '|| 'begin '|| ' if inserting then '|| ' if :NEW."WORKBOOK_ID" is null then '|| 21
  22. 22. ' select PJWBK_WBID_SEQ.nextval into :NEW."WORKBOOK_ID" from dual; '|| ' end if; '|| ' end if; '|| 'end;'; end; / /*creates the inventory table*/ create table inventory (inventory_id number, employee_id number, product_id number, QTY_Stocked Number, QTY_remaing Number, Stack_date date, next_stack_date number, constraint inventory_invid_pk primary key(inventory_id,employee_id, product_id), constraint invent_invid_uk unique (inventory_id), constraint invent_empid_fk foreign key(employee_id) references employee(employee_id), constraint invent_prodid_fk foreign key(product_id) references product(product_id) ); /* creates the sequence and the trigger to fire pk values upon inserts*/ create sequence inventory_invid_seq start with 21344 increment by 78 nocycle nocache order; begin execute immediate 'create or replace trigger inventor '|| ' before insert on "SYSTEM"."INVENTORY" '|| ' for each row '|| 'begin '|| ' if inserting then '|| 22
  23. 23. ' if :NEW."INVENTORY_ID" is null then '|| ' select INVENTORY_INVID_SEQ.nextval into :NEW."INVENTORY_ID" from dual; '|| ' end if; '|| ' end if; '|| 'end;'; end; / ---- Adjustments to the objects after they had been created.--------ALTER TABLE PRODUCT add PRODUCT_DESCRIPTION varchar2(2000); ALTER TABLE PRODUCT add account_name char(24); ALTER TABLE SALES MODIFY ORDER_DATE VARCHAR2(30); ALTER TABLE TRANSACTIONS MODIFY TRANS_DATE VARCHAR2(40); ALTER TABLE TRANSACTIONS MODIFY EXP_DATE VARCHAR2(40); ALTER TABLE INVENTORY MODIFY NEXT_STORAGE_DATE CHAR(40); ALTER TABLE INVENTORY ADD STORAGE_DATE CHAR(40); ALTER table hrrecord modify hire_date char(45); 23
  24. 24. ALTER TABLE HRRECORD MODIFY RANK VARCHAR2(45); ALTER TABLE DEPARTMENT MODIFY NAME VARCHAR2(40); ALTER TABLE CUSTOMERCARDS DROP COLUMN PRINT_EMPLOYEE_ID; ALTER TABLE CUSTOMER RENAME COLUMN TOTAL_CHILDREEN TO TOTAL_CHILDREN; ALTER TABLE CUSTOMERCARDSCLOSE ADD CUSTOMER_ID NUMBER; ALTER TABLE CUSTOMERCARDSCLOSE ADD CONSTRAINT CUSTCADCL_CUSTID_FK FOREIGN KEY(CUSTOMER_ID) REFERENCES CUSTOMER(CUSTOMER_ID); ALTER TABLE CUSTOMERCARDSCLOSE DROP PRIMARY KEY; ALTER TABLE CUSTOMERCARDSCLOSE ADD CONSTRAINT custclcad_pk primary key(serial_number, close_employee_Id, Account_Number); ALTER TABLE PROJECTS MODIFY PROJECT_TITLE VARCHAR2(200); ALTER TABLE INVENTORY RENAME COLUMN QTY_REMAING TO QTY_REMANING; ALTER TABLE INVENTORY MODIFY NEXT_STACK_DATE DATE; ALTER TABLE CUSTOMERCARDS MODIFY ACCOUNT_NUMBER CHAR(45); 24
  25. 25. ALTER TABLE CUSTOMERCARDSCLOSE MODIFY ACCOUNT_NUMBER CHAR(45); ALTER TABLE CUSTOMERCARDSCLOSE MODIFY CLOSE_DATE DATE; RENAME TRANSACTIONS TO TRANSHISTORY; UPDATETRANSHISTORY set exp_date = '09-march-2015'; ALTER TABLE authenticationemp RENAME COLUMN USER_NAME TO USERNAME; update department set manager_id = (select employee_id from hrrecord where employee_id = 50) where department_id = 653; Alter table authenticationemp Rename column employee_id to empid; /*This was done to make it easier to type username which is the same with the one found in database user directories */ Alter table authenticationem Rename colum user_name to username; /* This was done after the table has been created and populated to make it easier to remember*/ Rename authenticationemp to uemp; 25
  26. 26. TABLE POPULATION Insert statements for each of the tables. Please open them individually. EMPLOYEE_INSERTS.sql CUSTOMER_INSERTS.sql PRODUCT.sql TRANSACTION_SQL.txt SALES.sql department_insert.sql HRRCORD_INSERT.txt DATASETS.sql USER MANAGEMENT /*creates users*/ create user AlexHD identified by AlexdJHU password expire; 26
  27. 27. create user BrendaUDH identified by BrenDJK password expire; create user BerryHK identified by joeberr password expire; create user DavidMGI identified by Davortiz password expire; create user EricYMU identified by Ericjank password expire; create user SamarawickramaULP identified by Prasannasa password expire; create user RaymondPLK identified by SamRydmd password expire; create user AckermanJKP identified by PilarAcker password expire; create user RounthwaiteUHG identified by RobertRoun password expire; create user LiGeorgeTRW 27
  28. 28. identified by Georgehgy password expire; create user MichaelsThVY Identified by ThomasMichel password expire; create user AnnetteHiJ identified by hillannett password expire; create user NiswongerOIU identified by chadNwg; create user MohamedB2B identified by Mohamedshami password expire; create user RandallcythIK identified by cynthiaRnad password expire; create user MohansuOK identified by Suchitramsu password expire; create user IvoLKW identified by Salmreivo password expire; create user kaneVMP identified by kaneriol password expire; 28
  29. 29. create user ThierrydherLK identified by dhersthier password expire; create user PhilipsCLZ identified by Carolphilp password expire; create user caoJuIY identified by Junco password expire; create user fordjeffNK identified by jefferyfd password expire; CREATE USER STADICKDL identified by stadickbsty password expire; CREATE USER DAVYALOVSKY0 IDENTIFIED BY DVDB409 password expire; /*creates authentication table*/ create table authenticationEMP (EMPLOYEE_ID NUMBER, AUTHENTICATION_ID NUMBER, USER_NAME VARCHAR2(40), CONSTRAINT authent_authentpk primary key(Employee_id, authentication_id), constraint authent_employeeid_fk foreign key(employee_id) references employee(employee_id), constraint auth_username_uk unique (user_name), constraint auth_authentic_k unique (authentication_id) ); 29
  30. 30. /* creates the sequence to populate the primary key columns with a trigger defined below */ create sequence auth_authid_seq start with 0889373 increment by 203 nocycle order; begin execute immediate 'create or replace trigger AUTH '|| ' before insert on "SYSTEM"."AUTHENTICATIONEMP" '|| ' for each row '|| 'begin '|| ' if inserting then '|| ' if :NEW."AUTHENTICATION_ID" is null then '|| ' select AUTH_AUTHID_SEQ.nextval into :NEW."AUTHENTICATION_ID" from dual; '|| ' end if; '|| ' end if; '|| 'end;'; END; / INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 159, 'AlexHD'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID, USER_NAME) values(214,'BrendaUDH'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 264 ,'BerryHK'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 55, 'DavidMGI'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 245, 'EricYMU'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values(241, 'SamarawickramaULP' ); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 67, 'RaymondPLK'); 30
  31. 31. INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 87 ,'AckermanJKP'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 148, 'RounthwaiteUHG'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values(64, 'LiGeorgeTRW' ); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID ,USER_NAME) values( 198 , 'MichaelsThVY'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 268 ,'AnnetteHiJ'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 183, 'NiswongerOIU' ); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 138 ,'RandallcythIK'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID, USER_NAME) values( 70 ,'MohamedB2B'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 179, 'MohansuOK'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 28 ,'IvoLKW' ); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 201, 'kaneVMP'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID, USER_NAME) values( 6, 'ThierrydherLK'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 171, 'PhilipsCLZ'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 50, 'caoJuIY'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 17 , 'fordjeffNK'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID, USER_NAME) values(228, 'StadickDL'); INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 88 ,'DAVYALOVSKY0' ); 31
  32. 32. APPLICATION CONTEXT Employee Allows employee users to view their own records when they query certain table they have access like HRRecord, Employee and Projectwork. /* creates the application context*/ CREATE OR REPLACE CONTEXT EMPLOYE_SEC using EMPLYV1_CTX; /* creates the packages and procedures for the security context*/ create or replace package EMPLYV1_CTX AS PROCEDURE set_EMPID; PROCEDURE clear_EMPID; END EMPLYV1_CTX; / CREATE OR REPLACE PACKAGE BODY EMPLYV1_CTX AS ---------------------------------------PROCEDURE set_EMPID AS l_EMPID NUMBER; BEGIN SELECT EMPID 32
  33. 33. INTO l_EMPID FROM UEMP WHERE username = SYS_CONTEXT('USERENV', 'SESSION_USER'); DBMS_SESSION.SET_CONTEXT (namespace => 'EMPLOYE_SEC', ATTRIBUTE => 'EMPID', VALUE => l_EMPID); END set_EMPID; ----------------------------------------------PROCEDURE clear_EMPID AS BEGIN DBMS_SESSION.CLEAR_CONTEXT (namespace => 'EMPLOYE_SEC', ATTRIBUTE => 'EMPID'); END clear_EMPID; -----------------------------------------------------END EMPLYV1_CTX; / /* Creates the log in trigger that would validate user each time they log in to the database*/ CREATE OR REPLACE TRIGGER USRLOGIN AFTER LOGON ON DATABASE BEGIN system.EMPLYV1_CTX.SET_EMPID; EXCEPTION WHEN NO_DATA_FOUND THEN -- IF NO DATA IS FOUND, USER IS NOT IN THE DATABASE. --- MAY NOT BE ABLE TO LOGON. NULL; END; / 33
  34. 34. PASSWORD MANAGEMENT Password Authentication --------------------------Password Authentication---------------------------- /*creates the table to store and validate passwords*/ create table pwordauthenticate (username varchar2(45), passwd varchar2(45), verifier varchar2(30), constraint password_pword099_pk primary key (username, passwd) ); /*creates the index for username and the verifier*/ create index verifier on pwordauthenticate(username, verifier); /*creates the procedure to validate passwords*/ create or replace procedure feed_password (p_password in varchar2 default null) as l_new_password_verifier dba_users.PASSWORD%TYPE; l_password dba_users.PASSWORD%TYPE := UPPER (p_password); BEGIN FOR rec IN (SELECT username,password from dba_users) LOOP 34
  35. 35. IF (p_password is NULL) THEN ---PASSWORD IS EITHER PASSED AS PARAMETER OR SET SET USER'S NAME---l_password :=rec.username; END IF; -----CREATE NEW PASSWORD VERIFIER----------EXECUTE IMMEDIATE 'alter user' ||rec.username ||'identified by' ||l_password; ----RETERIVE NEW VERIFIER------------------------SELECT password into l_new_password_verifier from dba_users where username = rec.username; ---------------INSERT VALUE INTO PASSWORD TABLE-------INSERT INTO pwordauthenticate VALUES(rec.username, l_password, l_new_password_verifier); --set password back to its original value EXECUTE IMMEDIATE 'alter user' || rec.username ||'identified by values ''' || rec.password ||''''; end loop; end; / ------------------------------------------------end--------------------------------------. Password Requirements 35
  36. 36. Password requirement ensures that a user password meets the requirements established by the organization -----------------------Password Requirements----------------------------------/*creates the function to check the length and other requirements that a password must pass*/ create or replace function pword_strength (p_username varchar2, p_new_password varchar2, p_old_password varchar2) --- RETURN TRUE IF PASSWORD IS STRONG ENOUGH----RETURN BOOLEAN AS l_return_val BOOLEAN := TRUE; BEGIN ---CHECK TO BE SURE PASSWORD IS NOT THE SAME AS USERNAME---IF UPPER(p_new_password) = UPPER(p_username) THEN l_return_val :=FALSE; raise_application_error (-20001, 'Password same as username'); END IF; ----FORCES USER TO CHANGE PASSWORD TO SOMETHING NEW IF UPPER (p_new_password) = UPPER (p_old_password) THEN l_return_val :=FALSE; raise_application_error(-20004, 'Password has to be different then the old password'); END IF; 36
  37. 37. -- MAKE SURE PASSWORD IS NOT MADE UP OF NUMBERS ----IF(regexp_like(p_new_password, '[:alnum:]' ) = FALSE) THEN L_RETURN_VAL :=FALSE; raise_application_error (-20003 ,'Password must contain numbers, letters or character'); END IF; --MAKE SURE PASSWORD IS AT LEAST SIX CHARACTERS--IF LENGTH(p_new_password) <= 7 THEN l_return_val :=FALSE; raise_application_error(-20005, 'Password is too short'); END IF; RETURN l_return_val; END; / /* in real production the values would change to a higher value. This is set for testing reason.*/ CREATE PROFILE SPASSWORD LIMIT PASSWORD_LIFE_TIME 5 PASSWORD_GRACE_TIME 5 PASSWORD_REUSE_TIME 180 PASSWORD_REUSE_MAX UNLIMITED FAILED_LOGIN_ATTEMPTS 5 PASSWORD_LOCK_TIME .5 PASSWORD_VERIFY_FUNCTION pword_strength; -----------------------------end-------------------------------------- 37
  38. 38. AUDIT MANAGEMENT Ensures that database activities both by external and internal users are audited for recording purpose to maintain a good secured database state /*Enable the database audit */ Alter system set audit_trail=db_extended SCOPE=SPFILE; --------------------------AUDIT MANAGEMENT-------------------------------------------------------------------KEEPS TRACK OF USERS WHO ACCESSED THE DATABASE-----------BEGIN for rec IN (SELECT username, action_name, TO_CHAR(TIMESTAMP, 'Mon-DD HH24:MI') LOGON, TO_CHAR(logoff_time, 'Mon-DD HH24:MI') LOGOFF, priv_used, comment_text from dba_audit_trail) LOOP DBMS_OUTPUT.put_line('user: ' || rec.username); DBMS_OUTPUT.put_line('Action: ' || rec.action_name); DBMS_OUTPUT.put_line('Logon: ' || rec.LOGON); DBMS_OUTPUT.put_line('Logoff: ' || rec.LOGOFF); 38
  39. 39. DBMS_OUTPUT.put_line('priv_used: ' || rec.priv_used); DBMS_OUTPUT.put_line('comments: ' || rec.comment_text); DBMS_OUTPUT.put_line ('-------------------------------END of Record--------------------'); END LOOP; END; / --------------------------------------------------------------------------------------------------------------- --ADUITS USERS ACTIONS IN THE DATABASE---------------------------------------BEGIN FOR rec IN (SELECT audit_type, db_user, object_schema, object_name, extended_timestamp, sql_text from dba_common_audit_trail) LOOP DBMS_OUTPUT.put_line( 'Audit Type: ' || rec.audit_type); DBMS_OUTPUT.put_line( 'User: ' || rec.db_user); DBMS_OUTPUT.put_line('What: ' || rec.object_schema ||'.' || rec.object_name); DBMS_OUTPUT.put_line('When: ' || rec.extended_timestamp); 39
  40. 40. DBMS_OUTPUT.put_line('HOW: ' || rec.sql_text); DBMS_OUTPUT.put_line ('--------------------End Of Record--------------------'); END LOOP; END; / ----------------------------------------------------------------------------------- /* Audit was created after the views has been created illustrated in the next session*/ AUDIT SELECT, INSERT, UPDATE, DELETE ON EMPLOYEE BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON HRRECORD BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON CUSTOMER BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON PRODUCT BY ACCESS; AUDIT SELECT,INSERT, UPDATE, DELETE ON INVENTORY BY ACCESS; AUDIT SELECT,INSERT, UPDATE, DELETE ON TRANSHISTORY BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON SALES BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON ORDERS2 BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON CUSTOMERDATA BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON rCUSTOMERDATA BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON rorders BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON orders2 BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON EMPLOYEERV BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON EmployeeHR BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON PROJECTS BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON PROJECTWORKBOOK BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON PROJECT BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON PJWORK BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON CustCard BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON CARDCLOSE BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON customercards BY ACCESS; AUDIT SELECT, INSERT, UPDATE, DELETE ON customercardsclose BY ACCESS; 40
  41. 41. VIRTUAL PRIVATE DATABASE /*Creates the function to retrieve the employee id */ /*Allows employee to view the projects they have worked*/ Create or replace view projworkbook as select e.first_name , e.middle_name, e.last_name,d.name as department_name, p.hours_assign, p.role, j.project_title as Project_Tile, start_date, j.end_date,e.first_name||','||e.last_name as "Project Manager" from employee e inner join hrrecord h on h.employee_id = e.employee_id inner join department d on h.department_id = d.department_id inner join projects j on j.manager_id = e.employee_id inner join projectworkbook p on j.project_id = p.project_id; CREATE OR REPLACE FUNCTION EMPID_RET( p_schema IN VARCHAR2 DEFAULT NULL, p_object IN VARCHAR2 DEFAULT NULL) 41
  42. 42. RETURN VARCHAR2 AS BEGIN RETURN 'EMPID = SYS_CONTEXT (''EMPLOYE_SEC'',''EMPID'')'; END; / /*Allows employee to view all the projects they have worked*/ BEGIN DBMS_RLS.add_policy (object_schema =>‘SYSTEM’, OBJECT_NAME => 'projworkbook', POLICY_NAME => 'WORKBOOKPJ', FUNCTION_SCHEMA =>‘SYSTEM’, POLICY_FUNCTION => 'EMPID_RET', STATEMENT_TYPES => ' SELECT'); END; / DYNAMIC VIEW Allows users to create a restricted view based on their own user information /*create view that allows employee to see their basic information*/ create or replace view EmployeeRV AS 42
  43. 43. SELECT FIRST_NAME, MIDDLE_NAME, LAST_NAME, BIRTH_DATE, GENDER, EMPLOYEE_ID, MARITAL_STATUS, ADDRESS, CITY, STATE, POSTAL_CODE, PHONE FROM EMPLOYEE WHERE EMPLOYEE_ID = SYS_CONTEXT ('EMPLOYE_SEC','EMPID'); /*Restrict trigger to allow user update their own records*/ CREATE OR REPLACE TRIGGER DELUPD_RESTRICT_EMPLY BEFORE DELETE OR UPDATE ON EMPLOYEE FOR EACH ROW BEGIN IF(:OLD.EMPLOYEE_ID != SYS_CONTEXT ('EMPLOYE_SEC','EMPID')) THEN raise_application_error (-20001, CHR(10) || '** YOU CAN ONLY UPDATE YOUR OWN RECORD.' || CHR(10) ||'** YOUR EMPLOYEE ID IS' || SYS_CONTEXT ('EMPLOYE_SEC','EMPID') ); END IF; END; / /*create view to allow employee see their HR records*/ CREATE or replace view EmployeeHR AS SELECT E.FIRST_NAME ,E.MIDDLE_NAME ,E.LAST_NAME , H.SICK_HOURS, H.VACATION_HOURS, H.RANK, H.HIRE_DATE, H.PAY_RATE, H.OFFICE_PHONE, 43
  44. 44. D.NAME, G.FIRST_NAME||','||G.LAST_NAME AS "MANAGER_NAME" FROM EMPLOYEE E INNER JOIN HRRECORD H ON E.EMPLOYEE_ID = H.EMPLOYEE_ID INNER JOIN DEPARTMENT D ON H.DEPARTMENT_ID = D.DEPARTMENT_ID INNER JOIN EMPLOYEE G ON D.MANAGER_ID = G.EMPLOYEE_ID WHERE E.EMPLOYEE_ID = SYS_CONTEXT ('EMPLOYE_SEC','EMPID'); 44
  45. 45. NON-DYNAMIC VIEW /*Creates view used by customer representatives to query the database based on Account Card provided by the customer*/ CREATE VIEW CUSTOMERINFO AS SELECT A.ACCOUNT_NUMBER, A.CUSTOMER_ID, A.STATUS, C.FIRST_NAME, C.MIDDLE_NAME, C.LAST_NAME, C.ADDRESS, C.CITY, C.PHONE, C.STATE, C.BIRTH_DATE FROM CUSTOMERCARDS A INNER JOIN CUSTOMER C ON A.CUSTOMER_ID = C.CUSTOMER_ID; /*create view employee directory used by employee*/ Create view empdirectory as SELECT E.FIRST_NAME ||'-'||E.MIDDLE_NAME||','|| E.LAST_NAME AS EMPLOYEE, H.RANK, D.NAME AS "DEPARTMENT NAME", G.FIRST_NAME ||','||G.LAST_NAME AS "DEPARTMENT MANAGER" FROM EMPLOYEE E INNER JOIN HRRECORD H ON E.EMPLOYEE_ID = H.EMPLOYEE_ID INNER JOIN DEPARTMENT D 45
  46. 46. ON H.DEPARTMENT_ID = D.DEPARTMENT_ID INNER JOIN EMPLOYEE G ON G.EMPLOYEE_ID = D.MANAGER_ID ORDER BY D.DEPARTMENT_ID; /*create view used to retrieve others */ create view orders2rorders as SELECT C.FIRST_NAME ,C.MIDDLE_NAME,C.LAST_NAME ,C.CUSTOMER_ID, S.ORDER_ID, S.PRODUCT_ID, P.PRODUCT_NAME AS "NAME", S.QTY_ORDERED, S.PRODUCT_PRICE_ORIGINAL AS "Orginal-Price", S.TAX_AMOUNT_CHARGED AS "Tax", S.FREIGHT_AMOUNT_CHARGED AS "Shipping", S.TOTAL_AMOUNT AS "Final Amount", S.ORDER_DATE AS "Date-Ordered" from SALES S INNER JOIN CUSTOMER C ON S.CUSTOMER_ID = C.CUSTOMER_ID INNER JOIN PRODUCT P ON S.PRODUCT_ID = P.PRODUCT_ID; /* Create a view used by sales and marketing associates*/ CREATE VIEW CUSTOMERDATA AS SELECT c.customer_Id ,C.FIRST_NAME, C.MIDDLE_NAME, C.LAST_NAME, C.ADDRESS, C.CITY, C.PHONE, C.STATE, C.BIRTH_DATE FROM CUSTOMER C; 46
  47. 47. CREATE VIEW DEPARTMENTS AS SELECT E.FIRST_NAME ||','|| E.LAST_NAME AS MANAGER, D.NAME, H.OFFICE_PHONE FROM EMPLOYEE E INNER JOIN DEPARTMENT D ON E.EMPLOYEE_ID = D.MANAGER_ID INNER JOIN HRRECORD H ON H.EMPLOYEE_ID = E.EMPLOYEE_ID; /* Use by report analyst to crate reports. Again all the customers identifiers are removed.*/ create or replace view rorders as SELECT C.CUSTOMER_ID, S.ORDER_ID, S.PRODUCT_ID, P.PRODUCT_NAME AS "NAME", S.QTY_ORDERED, S.PRODUCT_PRICE_ORIGINAL AS "Orginal-Price", S.TAX_AMOUNT_CHARGED AS "Tax", S.FREIGHT_AMOUNT_CHARGED AS "Shipping", S.TOTAL_AMOUNT AS "Final Amount", S.ORDER_DATE AS "Date-Ordered" from SALES S INNER JOIN CUSTOMER C ON S.CUSTOMER_ID = C.CUSTOMER_ID INNER JOIN PRODUCT P ON S.PRODUCT_ID = P.PRODUCT_ID; CREATE or replace VIEW rCUSTOMERDATA 47
  48. 48. AS SELECT c.customer_Id, C.CITY, C.STATE, C.BIRTH_DATE, C.POSTAL_CODE, C.COUNTRY, C.GENDER, C.YEARLY_INCOME, C.MARITAL_STATUS , C.EDUCATIONAL_BACKGROUND ,C.TOTAL_CHILDREN ,C.TOTAL_CARS_OWNED,C.PROFESSION FROM CUSTOMER C; DATABASE MANAGEMENT /* Grant create session to employees */ GRANT CREATE SESSION TO BrendaUDH; GRANT CREATE SESSION TO BerryHK; GRANT CREATE SESSION TO DavidMGI; GRANT CREATE SESSION TO EricYMU; GRANT CREATE SESSION TO SamarawickramaULP; GRANT CREATE SESSION TO RaymondPLK; GRANT CREATE SESSION TO AckermanJKP; GRANT CREATE SESSION TO RounthwaiteUHG; GRANT CREATE SESSION TO LiGeorgeTRW; GRANT CREATE SESSION TO MichaelsThVY; GRANT CREATE SESSION TO AnnetteHiJ; GRANT CREATE SESSION TO NiswongerOIU; GRANT CREATE SESSION TO MohamedB2B; GRANT CREATE SESSION TO RandallcythIK; GRANT CREATE SESSION TO MohansuOK; 48
  49. 49. GRANT CREATE SESSION TO IvoLKW; GRANT CREATE SESSION TO kaneVMP; GRANT CREATE SESSION TO ThierrydherLK; GRANT CREATE SESSION TO PhilipsCLZ; GRANT CREATE SESSION TO caoJuIY; GRANT CREATE SESSION TO fordjeffNK; GRANT CREATE SESSION TO STADICKDL; GRANT CREATE SESSION TO DAVYALOVSKY0; /* Human Resources */ Create ROLE HR; Grant select, update , insert on HRRECORD to HR; Create or replace public synonym employee for employee; Grant SELECT , INSERT, UPDATE on employee to HR; Grant HR TO MohansuOK; /*Accountant*/ CREATE ROLE ACCOUNTANTS; CREATE OR REPLACE PUBLIC SYNONYM TRANSACTIONS FOR TRANSHISTORY; CREATE OR REPLACE PUBLIC SYNONYM SALES FOR SALES; CREATE OR REPLACE PUBLIC SYNONYM ORDER1 FOR ORDERS2; CREATE OR REPLACE PUBLIC SYNONYM CUSTDATA01 FOR CUSTOMERDATA; GRANT SELECT, UPDATE ON TRANSACTIONS TO ACCOUNTANTS; GRANT SELECT, UPDATE ON SALES TO ACCOUNTANTS; GRANT SELECT, UPDATE ON ORDER1 TO ACCOUNTANTS; GRANT SELECT ON CUSTDATA01 TO ACCOUNTANTS; GRANT ACCOUNTANTS TO AckermanJKP; GRANT ACCOUNTANTS TO RaymondPLK; GRANT ACCOUNTANTS TO kaneVMP; 49
  50. 50. /*RANALYST*/ CREATE ROLE RANALYST; CREATE OR REPLACE PUBLIC SYNONYM CUSTDATA02 FOR rCUSTOMERDATA ; GRANT SELECT ON CUSTDATA02 TO RANALYST; CREATE OR REPLACE PUBLIC SYNONYM ORDERS04 FOR rorders; GRANT SELECT ON ORDERS04 TO RANALYST; Grant RANALYST to DavidMGI; /*--SALES*/ CREATE ROLE SALES; GRANT SELECT ON TRANSACTIONS TO SALES; GRANT SELECT ON SALES TO SALES; GRANT SELECT ON ORDER1 TO SALES; GRANT SELECT ON CUSTDATA01 TO SALES; CREATE OR REPLACE PUBLIC SYNONYM PRODT FOR PRODUCT; GRANT SELECT, UPDATE, INSERT ON PRODT TO SALES; CREATE OR REPLACE PUBLIC SYNONYM INVENT FOR INVENTORY; CREATE OR REPLACE PUBLIC SYNONYM INVENT FOR INVENTORY; GRANT SELECT, UPDATE(PRODUCT_ID, NEXT_STACK_DATE, QTY_REMANING), INSERT ON INVENT TO SALES; GRANT SALES TO MohamedB2B; GRANT SALES TO ThierrydherLK ; /*--CUSTOMER REP*/ 50
  51. 51. CREATE ROLE CUSTOMERREP; CREATE OR REPLACE PUBLIC SYNONYM CUSTINFO FOR CUSTOMERINFO; GRANT SELECT, INSERT, UPDATE ON CUSTINFO TO CUSTOMERREP; CREATE OR REPLACE PUBLIC SYNONYM orders08 FOR orders2; GRANT SELECT, UPDATE ON orders08 to customerrep; GRANT CUSTOMERREP TO NiswongerOIU; GRANT CUSTOMERREP TO PhilipsCLZ; /*-Employees */ CREATE ROLE EMPLOYEE; /*EMPLOYEE DYNAMIC AND NON DYNAMIC VIEWS*/ CREATE OR REPLACE PUBLIC SYNONYM EMPLOYEERV FOR EMPLOYEERV; GRANT SELECT, UPDATE, INSERT ON EMPLOYEERV TO EMPLOYEE ; CREATE OR REPLACE PUBLIC SYNONYM EmployeeHR FOR EmployeeHR; GRANT SELECT, UPDATE, INSERT ON EmployeeHR TO EMPLOYEE; CREATE OR REPLACE PUBLIC SYNONYM EMPDIRECTORY FOR empdirectory; GRANT SELECT ON EMPDIRECTORY TO EMPLOYEE; CREATE OR REPLACE PUBLIC SYNONYM WORKBOOK FOR GRANT GRANT GRANT GRANT GRANT EMPLOYEE TO AlexHD; EMPLOYEE TO BerryHK; EMPLOYEE TO DavidMGI; EMPLOYEE TO EricYMU; EMPLOYEE To SamarawickramaULP; projworkbook; 51
  52. 52. GRANT EMPLOYEE TO RaymondPLK; GRANT EMPLOYEE TO AckermanJKP; GRANT EMPLOYEE TO RounthwaiteUHG; GRANT EMPLOYEE TO MichaelsThVY; GRANT EMPLOYEE TO AnnetteHiJ; GRANT EMPLOYEE TO NiswongerOIU; GRANT EMPLOYEE TO RandallcythIK; GRANT EMPLOYEE TO MohamedB2B; GRANT EMPLOYEE TO MohansuOK; GRANT EMPLOYEE TO IvoLKW; GRANT EMPLOYEE TO kaneVMP; GRANT EMPLOYEE TO ThierrydherLK; GRANT EMPLOYEE TO PhilipsCLZ; GRANT EMPLOYEE TO caoJuIY; GRANT EMPLOYEE TO fordjeffNK; GRANT EMPLOYEE TO StadickDL; GRANT EMPLOYEE TO DAVYALOVSKY0; GRANT EMPLOYEE TO BrendaUDH; /*-PROJECT MANAGERS*/ CREATE ROLE PJM; CREATE OR REPLACE PUBLIC SYNONYM PROJECT FOR PROJECTS; CREATE OR REPLACE PUBLIC SYNONYM PJWORK FOR PROJECTWORKBOOK; GRANT SELECT, INSERT, UPDATE ON PROJECT TO PJM; GRANT SELECT , INSERT, UPDATE ON PJWORK TO PJM; GRANT PJM TO StadickDL; GRANT PJM TO AnnetteHiJ; ------------------PART 2------------------------------------------------------- 52
  53. 53. CREATE OR REPLACE PUBLIC SYNONYM CustCard for customercards; CREATE OR REPLACE public SYNONYM CARDCLOSE FOR customercardsclose; GRANT SELECT, UPDATE(STATUS), INSERT ON CustCard to CUSTOMERREP; GRANT SELECT, INSERT ON CARDCLOSE TO CUSTOMERREP; GRANT SELECT, UPDATE(STATUS), INSERT ON CustCard TO ACCOUNTANTS; GRANT SELECT ON CARDCLOSE TO ACCOUNTANTS; CREATE ROLE DB; GRANT DB TO DAVYALOVSKY0; GRANT DBA TO DAVYALOVSKY0; 53
  54. 54. IMPLEMENNTATION 54
  55. 55. DATABASE CREATION /************************** Spool files of table, synonym, triggers and sequence creations *********************/ SQL> show user USER is "SYSTEM" SQL> SQL> 2 3 4 5 6 7 8 9 10 11 12 13 14 15 create table EMPLOYEE (Employee_ID Number constraint employeeid_pk primary key, First_Name Varchar2(30), Middle_Name Varchar2(30), Last_Name Varchar2(30), Birth_Date varchar2(45), Gender Char(15), Marital_status Char(20), Address Varchar2(50), City Varchar2(35), State varchar(35), Postal_Code varchar2(20), Phone Varchar2(25), National_ID NUMBER ); Table created. SQL> /* Adds the customer column to the employee table*/ SQL> SQL> Alter table employee 2 add customer_id number; Table altered. SQL> /* adds the not null constraint */ SQL> Alter table employee 2 modify(first_name constraint empl_fname_nn not null) 3 modify(middle_name constraint empl_midname_nn not null) 4 modify(last_name constraint empl_lastname_nn not null) 5 modify(birth_date constraint empl_birthdate_nn not null) 6 modify(gender constraint empl_gender_nn not null) 7 modify(address constraint empl_address_nn not null) 8 modify(city constraint empl_city_nn not null) 55
  56. 56. 9 10 11 12 modify(state constraint empl_state_nn not null) modify(postal_code constraint empl_postalcode_nn not null) modify(National_id constraint empl_nationalid_nn not null) modify(phone constraint empl_phone_nn not null); Table altered. SQL> SQL> CREATE SEQUENCE EMPNATIONALID_SEQ INCREMENT BY 120 start with 018892343 nocache nocycle order; Sequence created. SQL> SQL> SQL> 2 3 4 5 6 7 8 9 10 11 12 13 /* creates the trigger to automatically populate the national id column */ begin execute immediate 'create or replace trigger nationalid '|| ' before insert on "SYSTEM"."EMPLOYEE" '|| ' for each row '|| 'begin '|| ' if inserting then '|| ' if :NEW."NATIONAL_ID" is null then '|| ' select EMPNATIONALID_SEQ.nextval into :NEW."NATIONAL_ID" from dual; '|| ' end if; '|| ' end if; '|| 'end;'; end; / PL/SQL procedure successfully completed. SQL> /* creates the public snyonym for employee*/ SQL> SQL> create public synonym employee for employee; Synonym created. SQL> SQL> 2 3 4 5 6 7 8 9 10 11 create table customer (Customer_ID number constraint custo_custid_pk primary key, First_Name Varchar2(35), Middle_Name Varchar2(35), Last_Name Varchar2(35), Gender Char(15), Birth_Date Varchar2(45), Yearly_Income Number, Total_Childreen Number, Total_Cars_Owned Number, Marital_Status Varchar2(35), 56
  57. 57. 12 13 14 15 16 17 18 19 20 profession varchar2(34), Address Varchar2(50), City Varchar2(20), State char(35), Postal_Code varchar2(20), country varchar2(35), Phone Varchar2(25), Educational_Background varchar2(35) ); Table created. SQL> Alter table employee 2 add constraint emp_custid_fk foreign key(customer_id) references 3 customer(customer_id); Table altered. SQL> SQL> SQL> Alter table customer 2 modify(first_name constraint cust_firstname_nn not null) 3 modify(middle_name constraint cust_midname_nn not null) 4 modify(last_name constraint cust_lastname_nn not null) 5 modify(birth_date constraint cust_birthdate_nn not null) 6 modify(gender constraint cust_gender_nn not null) 7 modify(address constraint cust_address_nn not null) 8 modify(city constraint cust_city_nn not null) 9 modify(state constraint cust_state_nn not null) 10 modify(postal_code constraint cust_postalcode_nn not null) 11 modify(phone constraint cust__phone_nn not null); Table altered. SQL> SQL> SQL> SQL> /* creates the public synonym for customer */ create public synonym customer for customer; Synonym created. SQL> SQL> SQL> SQL> 2 3 4 5 /* creates the department table*/ CREATE TABLE DEPARTMENT (DEPARTMENT_ID NUMBER, NAME VARCHAR(20), MANAGER_ID NUMBER, CONSTRAINT DEPART_DEPARTSTRID_PK PRIMARY KEY(DEPARTMENT_ID), 57
  58. 58. 6 CONSTRAINT DEPTART_MANGID_FK FOREIGN KEY(MANAGER_ID) REFERENCES EMPLOYEE(EMPLOYEE_ID) 7 ); Table created. SQL> SQL> /* creates the not null constraint to the department table */ SQL> SQL> Alter table Department 2 modify(department_id constraint dept_departid_nn not null ) 3 modify(name constraint dept_name_nn not null); Table altered. SQL> CREATE PUBLIC SYNONYM DEPARTMENT FOR DEPARTMENT; Synonym created. SQL> SQL> /* create the sequence for the department id column and the trigger to automatically populate it*/ SQL> SQL> CREATE SEQUENCE depart_deptid_seq increment by 89 start with 208 NOCYCLE nocache order; Sequence created. SQL> SQL> begin 2 execute immediate 'create or replace trigger deptid_trgg '|| 3 ' before insert on "SYSTEM"."DEPARTMENT" '|| 4 ' for each row '|| 5 'begin '|| 6 ' if inserting then '|| 7 ' if :NEW."DEPARTMENT_ID" is null then '|| 8 ' select DEPART_DEPTID_SEQ.nextval into :NEW."DEPARTMENT_ID" from dual; '|| 9 ' end if; '|| 10 ' end if; '|| 11 'end;'; 12 end; 13 14 / PL/SQL procedure successfully completed. SQL> 2 3 4 CREATE TABLE HRRECORD (EMPLOYEE_ID NUMBER, HR_ID NUMBER, DEPARTMENT_ID NUMBER, 58
  59. 59. 5 SICK_HOURS NUMBER, 6 VACATION_HOURS NUMBER, 7 RANK CHAR(30), 8 HIRE_DATE DATE, 9 PAY_RATE NUMBER, 10 Office_Phone varchar2(35), 11 CONSTRAINT HRREC_EMPHRID_PK PRIMARY KEY(EMPLOYEE_ID, HR_ID, DEPARTMENT_ID), 12 CONSTRAINT HRREC_EMPHIRIDUK_UK UNIQUE (HR_ID), 13 CONSTRAINT HRREC_HRDEPTID_FK FOREIGN KEY(DEPARTMENT_ID)REFERENCES DEPARTMENT(DEPARTMENT_ID) ON DELETE CASCADE, 14 CONSTRAINT HRREC_EMPLOYEEID_FK FOREIGN KEY(EMPLOYEE_ID) REFERENCES EMPLOYEE (EMPLOYEE_ID) ON DELETE CASCADE 15 ); Table created. SQL> SQL> CREATE PUBLIC SYNONYM HRRECORD FOR HRRECORD; Synonym created. SQL> SQL> SQL> SQL> /* creates the sequences to create primary key values and the trigger to generate them automatically*/ SQL> SQL> CREATE SEQUENCE HR_HRID_SEQ increment by 887977 start with 268 NOCYCLE nocache order; Sequence created. SQL> SQL> begin 2 execute immediate 'create or replace trigger hrrid2_trgg '|| 3 ' before insert on "SYSTEM"."HRRECORD" '|| 4 ' for each row '|| 5 'begin '|| 6 ' if inserting then '|| 7 ' if :NEW."HR_ID" is null then '|| 8 ' select HR_HRID_SEQ.nextval into :NEW."HR_ID" from dual; '|| 9 ' end if; '|| 10 ' end if; '|| 11 'end;'; 12 end; 13 14 / PL/SQL procedure successfully completed. SQL> SQL> /* creates the table product to hold all data relating to a product*/ 59
  60. 60. SQL> SQL> 2 3 4 5 6 7 8 Create table product (Product_ID Number constraint prod_prodnumber_nn not null, product_Name varchar2(90), Product_Price number, Product_Brand Varchar2(35), Product_Description CLOB, Product_Category varchar2(30) ); Table created. SQL> SQL> SQL> SQL> 2 3 4 /* creates the not null and primary key constraint */ Alter table product modify(Product_Price constraint prod_prodcost_nn not null) modify(product_name constraint prod_prodname_nn not null) modify(Product_Category constraint prod_prodcategory_nn not null); Table altered. SQL> SQL> 2 Alter table product modify(product_id constraint prod_productid_pk primary key); Table altered. SQL> SQL> /*creates the tansactions table */ SQL> SQL> 2 3 4 5 6 7 8 9 10 create table transactions (Transacton_ID VARCHAR2(60), Credit_Card_ID Number, Card_Type char(24), EXP_DATE DATE, Trans_Date Date, Amount_Charged Number, Brand Char(20), Constraint trans_transactionsid_pk ); PRIMARY KEY (Transacton_ID) Table created. /*creates the sequece used to populate the credit card values */ create sequence creditcard start with 1200007800002345 increment by 809 nocycle nocache order; 60
  61. 61. create sequence succeeded. begin execute immediate 'create or replace trigger ccredit '|| ' before insert on "SYSTEM"."TRANSACTIONS" '|| ' for each row '|| 'begin '|| ' if inserting then '|| ' if :NEW."CREDIT_CARD_ID" is null then '|| ' select CREDITCARD.nextval into :NEW."CREDIT_CARD_ID" from dual; '|| ' end if; '|| ' end if; '|| 'end;'; end; / anonymous block completed SQL> SQL> /*Create the sales table */ SQL> SQL> create table sales 2 (Customer_id number, 3 Transacton_ID VARCHAR2(60), 4 Product_id number, 5 Order_ID Number, 6 QTY_Ordered number, 7 Product_Price_Original number, 8 Product_price_WT_QTY number, 9 Tax_Amount_Charged Number, 10 Freight_Amount_charged number, 11 Total_Amount Number, 12 Order_Date Date, 13 Constraint sales_custprodidtrand_pk primary key(customer_id, product_id, Transacton_ID, order_id) 14 , constraint sales_salid_uk unique(Order_id) 15 , constraint sales_custid_fk foreign key(customer_id) references customer(customer_id) on delete cascade, 16 constraint sales_pproductid_fk foreign key(product_id) references product(product_id) on delete cascade 17 ); Table created. SQL> SQL> /* adds the foreign key constraint linking transaction to sales table */ 61
  62. 62. SQL> Alter table sales 2 add constraint saltransidU_fk foreign key (Transacton_ID) references transactions(Transacton_ID); Table altered. SQL> /*creates table to hold all customer card information*/ create table customercards (Account_Number Number, customer_id Number, print_date date, print_employee_id number, status char(20), employee_id number, constraint custcard_empid_fk foreign key(print_employee_id) references employee(employee_id), constraint custcards_pk primary key (Account_Number,Customer_id, employee_Id), constraint custcards_custid_fk foreign key (customer_id) references customer(customer_id), constraint custcards_empid_fk foreign key(employee_id) references employee(employee_id), constraint custcard_ser_uk unique(Account_Number) ) create table succeeded. /*creates the table to hold all cards closed or lost reported by customer*/ create table customercardsclose (serial_number number, Account_Number number, close_employee_ID number, close_date number, notes clob, constraint custclcad_pk primary key(serial_number,Account_Number), constraint custclcad_sernum_uk unique (serial_number), constraint custclad_cempid_fk foreign key(close_employee_ID) references employee(employee_id) ) create table succeeded. /*creates the table to hold all projects the company are working or has worked on*/ create table projects (project_id number, Manager_id Number, project_title number, start_date date, end_date date, Awarded_Amount number, notes clob, 62
  63. 63. constraint project_proj_pk primary key (project_id, manager_id), constraint project_magid_fk foreign key(manager_id) references employee(employee_id), constraint project_projid_uk unique (project_id) ) create table succeeded. /*creates the sequence to populate the fire automatic inserts*/ peoject_id column of projects and the trigger to create sequence projet_projeid_sq start with 054456 order nocycle nocache increment by 56 create sequence succeeded. begin execute immediate 'create or replace trigger project_trgg '|| ' before insert on "SYSTEM"."PROJECTS" '|| ' for each row '|| 'begin '|| ' if inserting then '|| ' if :NEW."PROJECT_ID" is null then '|| ' select PROJET_PROJEID_SQ.nextval into :NEW."PROJECT_ID" from dual; '|| ' end if; '|| ' end if; '|| 'end;'; END; anonymous block completed /*creates the project work book table to hold all important information relating to a project*/ create table Projectworkbook (project_id number, employee_id number, workbook_id number, Hours_Assign Number, Role varchar2(40), constraint projwork_pk primary key(employee_id, project_id, workbook_id), constraint projwork_wbk_uk unique (workbook_id), constraint projwork_wb_fk foreign key(project_id) references projects(project_id) constraint projwork_emp_id_fk foreign key(employee_id) references employee(employee_id) ); create table succeeded. /*creates the sequence and trigger to fire inserts for pk column*/ create sequence pjwbk_wbid_seq start with 06745 increment by 34 nocycle order nocache 63
  64. 64. create sequence succeeded. begin execute immediate 'create or replace trigger pjworkbook '|| ' before insert on "SYSTEM"."PROJECTWORKBOOK" '|| ' for each row '|| 'begin '|| ' if inserting then '|| ' if :NEW."WORKBOOK_ID" is null then '|| ' select PJWBK_WBID_SEQ.nextval into :NEW."WORKBOOK_ID" from dual; '|| ' end if; '|| ' end if; '|| 'end;'; END; / anonymous block completed /*creates the inventory table*/ create table inventory (inventory_id number, employee_id number, product_id number, QTY_Stocked Number, QTY_remaing Number, Stack_date date, next_stack_date number, constraint inventory_invid_pk primary key(inventory_id,employee_id, product_id), constraint invent_invid_uk unique (inventory_id), constraint invent_empid_fk foreign key(employee_id) references employee(employee_id), constraint invent_prodid_fk foreign key(product_id) references product(product_id) ) create table succeeded. /* creates the sequence and the trigger to fire pk values upon inserts*/ create sequence inventory_invid_seq start with 21344 order increment by 78 nocycle nocache create sequence succeeded. begin execute immediate 'create or replace trigger inventor ' before insert on "SYSTEM"."INVENTORY" '|| ' for each row '|| 'begin '|| '|| 64
  65. 65. ' if inserting then '|| ' if :NEW."INVENTORY_ID" is null then '|| ' select INVENTORY_INVID_SEQ.nextval into :NEW."INVENTORY_ID" from dual; '|| ' end if; '|| ' end if; '|| 'end;'; end; / anonymous block completed SQL> set echo off; SQL> spool off; /****************************************END OF SPOOL FILE 1***********************************************************/ TABLE POPULATION Employee Insert Statement EMPLOYEEINSERT.SQL Customer Insert Statement CUSTOMERINSERT.SQL Product Insert Statement SQL loader was used to insert the product data. Please see the attached control and log files. product.ctl product.log product.sh Transaction Insert Statement TRANSACTION_FN.SQL 65
  66. 66. Sales Insert Statement SAL_FN.SQL Department Insert Statement DEPARTMENT.SQL Hrrecord Insert Statement HR_FN.SQL Project and Project Workbook PROJECT_SPOOL.SQL Inventory inventory_spool.sql CustomerCards and Customercardsclose customer_card_spool.sql USER MANAGEMENT SQL> show user USER is "DAVYALOVSKY0" SQL> SQL> 2 3 User create user AlexHD identified by AlexdJHU password expire; created. SQL> SQL> create user BrendaUDH 2 identified by BrenDJK 66
  67. 67. 3 password expire; User created. SQL> SQL> create user BerryHK 2 identified by joeberr 3 password expire; User created. SQL> SQL> create user DavidMGI 2 identified by Davortiz 3 password expire; User created. SQL> SQL> create user EricYMU 2 identified by Ericjank 3 password expire; User created. SQL> SQL> create user SamarawickramaULP 2 identified by Prasannasa 3 password expire; User created. SQL> SQL> create user RaymondPLK 2 identified by SamRydmd 3 password expire; User created. SQL> SQL> create user AckermanJKP 2 identified by PilarAcker 3 password expire; User created. SQL> SQL> create user RounthwaiteUHG 2 identified by RobertRoun 3 password expire; 67
  68. 68. User created. SQL> SQL> create user LiGeorgeTRW 2 identified by Georgehgy 3 password expire; User created. SQL> SQL> SQL> 2 3 User create user MichaelsThVY identified by ThomasMichel password expire; created SQL> SQL> SQL> create user AnnetteHiJ 2 identified by hillannett 3 password expire; User created. SQL> SQL> create user NiswongerOIU 2 identified by chadNwg 3 password expire; User created. SQL> SQL> create user MohamedB2B 2 identified by Mohamedshami 3 password expire; User created. SQL> SQL> create user RandallcythIK 2 identified by cynthiaRnad 3 password expire; User created. SQL> SQL> create user MohansuOK 2 identified by Suchitramsu 3 password expire; User created. 68
  69. 69. SQL> SQL> create user IvoLKW 2 identified by Salmreivo 3 password expire; User created. SQL> SQL> create user kaneVMP 2 identified by kaneriol 3 password expire; User created. SQL> SQL> create user ThierrydherLK 2 identified by dhersthier 3 password expire; User created. SQL> SQL> create user PhilipsCLZ 2 identified by Carolphilp 3 password expire; User created. SQL> SQL> create user caoJuIY 2 identified by Junco 3 password expire; User created. SQL> SQL> create user fordjeffNK 2 identified by jefferyfd 3 password expire; User created. SQL> SQL> CREATE USER STADICKDL 2 identified by stadickbsty 3 password expire; User created. SQL> 69
  70. 70. SQL> SQL> /*creates authentication table*/ SQL> SQL> create table authenticationEMP 2 (EMPLOYEE_ID NUMBER, 3 AUTHENTICATION_ID NUMBER, 4 USER_NAME VARCHAR2(40), 5 CONSTRAINT authent_authentpk primary key(Employee_id, authentication_id), 6 constraint authent_employeeid_fk foreign key(employee_id) references employee(employee_id), 7 constraint auth_username_uk unique (user_name), 8 constraint auth_authentic_k unique (authentication_id) 9 ); Table created. SQL> /* creates the sequence to populate the primary key columns with a trigger defined below */ SQL> SQL> create sequence auth_authid_seq start with 0889373 increment by 203 nocycle order; Sequence created. SQL> SQL> SQL> begin 2 execute immediate 'create or replace trigger AUTH '|| 3 ' before insert on "DAVYALOVSKY0"."AUTHENTICATIONEMP" '|| 4 ' for each row '|| 5 'begin '|| 6 ' if inserting then '|| 7 ' if :NEW."AUTHENTICATION_ID" is null then '|| 8 ' select AUTH_AUTHID_SEQ.nextval into :NEW."AUTHENTICATION_ID" from dual; '|| 9 ' end if; '|| 10 ' end if; '|| 11 'end;'; 12 END; 13 / PL/SQL procedure successfully completed. SQL> SQL> SQL> SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) 2 values( 159, 'AlexHD'); 70
  71. 71. 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID, USER_NAME) 2 values(214,'BrendaUDH'); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) 2 values( 264 ,'BerryHK'); 1 row created. SQL> 2 INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 55, 'DavidMGI'); 1 row created. SQL> 2 INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) values( 245, 'EricYMU'); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) 2 values(241, 'SamarawickramaULP' ); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) 2 values( 67, 'RaymondPLK'); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) 2 values( 87 ,'AckermanJKP'); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) 2 values( 148, 'RounthwaiteUHG'); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) 2 values(64 'LiGeorgeTRW' ); values(64 'LiGeorgeTRW' ) * ERROR at line 2: ORA-00917: missing comma SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID ,USER_NAME) 71
  72. 72. 2 values( 198 , 'MichaelsThVY'); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) 2 values( 268 ,'AnnetteHiJ'); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) 2 values( 183, 'NiswongerOIU' ); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) 2 values( 138 ,'RandallcythIK'); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID, USER_NAME) 2 values( 70 ,'MohamedB2B'); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) 2 values( 179, 'MohansuOK'); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) 2 values( 28 ,'IvoLKW' ); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) 2 values( 201, 'kaneVMP'); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID, USER_NAME) 2 values( 6, 'ThierrydherLK'); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) 2 values( 171, 'PhilipsCLZ'); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) 2 values( 50, 'caoJuIY'); 72
  73. 73. 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) 2 values( 17 , 'fordjeffNK'); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID, USER_NAME) 2 values(228, 'StadickDL'); 1 row created. SQL> INSERT INTO AUTHENTICATIONEMP(EMPLOYEE_ID,USER_NAME) 2 values( 88 ,'DAVYALOVSKY0' ); 1 row created. SQL> commit; Commit complete. SQL> set echo off SQL> spool off; APPLICATION CONTEXT > CREATE OR REPLACE CONTEXT EMPLOYE_SEC context EMPLOYE_SEC created. using EMPLYV1_CTX > create or replace package EMPLYV1_CTX AS PROCEDURE set_EMPID; PROCEDURE clear_EMPID; END EMPLYV1_CTX; PACKAGE EMPLYV1_CTX compiled > CREATE OR REPLACE PACKAGE BODY EMPLYV1_CTX AS ---------------------------------------PROCEDURE set_EMPID AS 73
  74. 74. l_EMPID NUMBER; BEGIN SELECT EMPID INTO l_EMPID FROM UEMP WHERE username = SYS_CONTEXT('USERENV', 'SESSION_USER'); DBMS_SESSION.SET_CONTEXT (namespace => 'EMPLOYE_SEC', ATTRIBUTE => 'EMPID', VALUE => l_EMPID); END set_EMPID; ----------------------------------------------PROCEDURE clear_EMPID AS BEGIN DBMS_SESSION.CLEAR_CONTEXT (namespace => 'EMPLOYE_SEC', ATTRIBUTE => 'EMPID'); END clear_EMPID; -----------------------------------------------------END EMPLYV1_CTX; PACKAGE BODY EMPLYV1_CTX compiled > CREATE OR REPLACE TRIGGER USRLOGIN AFTER LOGON ON DATABASE BEGIN system.EMPLYV1_CTX.set_EMPID; EXCEPTION WHEN NO_DATA_FOUND THEN -- IF NO DATA IS FOUND, USER IS NOT IN THE DATABASE. --- MAY NOT BE ABLE TO LOGON. NULL; END; TRIGGER USRLOGIN compiled PASSWORD MANAGEMENT Password Authentication --------------------------Password Authentication---------------------------/*creates the table to store and validate passwords*/ create table pwordauthenticate (username varchar2(45), passwd varchar2(45), verifier varchar2(30), constraint password_pword099_pk primary key (username, passwd) ) create table succeeded. 74
  75. 75. /*creates the index for username and the verifier*/ create index verifier on pwordauthenticate(username, verifier) create index succeeded. /*creates the procedure to validate passwords*/ create or replace procedure feed_password (p_password in varchar2 default null) as l_new_password_verifier dba_users.PASSWORD%TYPE; l_password dba_users.PASSWORD%TYPE := UPPER (p_password); BEGIN FOR rec IN (SELECT username,password from dba_users) LOOP IF (p_password is NULL) THEN ---PASSWORD IS EITHER PASSED AS PARAMETER OR SET SET USER'S NAME---l_password :=rec.username; END IF; -----CREATE NEW PASSWORD VERIFIER----------EXECUTE IMMEDIATE 'Alter user' ||rec.username ||'identified by' ||l_password; ----RETERIVE NEW VERIFIER------------------------SELECT password into l_new_password_verifier from dba_users where username = rec.username; ---------------INSERT VALUE INTO PASSWORD TABLE-------INSERT INTO pwordauthenticate VALUES(rec.username, l_password, l_new_password_verifier); --set password back to its original value EXECUTE IMMEDIATE 'alter user' || rec.username ||'identified by values ''' || rec.password ||''''; end loop; end; PROCEDURE FEED_PASSWORD compiled ------------------------------------------------end--------------------------------------Password Requirements create or replace function pword_strength (p_username varchar2, p_new_password varchar2, p_old_password varchar2) 75
  76. 76. --- RETURN TRUE IF PASSWORD IS STRONG ENOUGH----RETURN BOOLEAN AS l_return_val BOOLEAN := TRUE; BEGIN ---CHECK TO BE SURE PASSWORD IS NOT THE SAME AS USERNAME---IF UPPER(p_new_password) = UPPER(p_username) THEN l_return_val :=FALSE; raise_application_error (-20001, 'Password same as username'); END IF; ----FORCES USER TO CHANGE PASSWORD TO SOMETHING NEW IF UPPER (p_new_password) = UPPER (p_old_password) THEN l_return_val :=FALSE; raise_application_error(-20004, 'Password has to be different then the old password'); END IF; -- MAKE SURE PASSWORD IS NOT MADE UP OF NUMBERS ----IF(regexp_like(p_new_password, '[:alnum:]' ) = FALSE) THEN L_RETURN_VAL :=FALSE; raise_application_error (-20003 ,'Password must contain numbers, letters or character'); END IF; --MAKE SURE PASSWORD IS AT LEAST SIX CHARACTERS--IF LENGTH(p_new_password) <= 7 THEN l_return_val :=FALSE; raise_application_error(-20005, 'Password is too short'); END IF; RETURN l_return_val; END; / /* in real production the values would change to a higher value. This is set for testing reason.*/ CREATE PROFILE SPASSWORD LIMIT PASSWORD_LIFE_TIME 5 PASSWORD_GRACE_TIME 5 PASSWORD_REUSE_TIME 180 PASSWORD_REUSE_MAX UNLIMITED FAILED_LOGIN_ATTEMPTS 5 PASSWORD_LOCK_TIME .5 PASSWORD_VERIFY_FUNCTION pword_strength; -----------------------------end-----------------------------------------------FUNCTION pword_strength compiled profile SPASSWORD created. AUDIT MANAGEMENT 76
  77. 77. ---KEEPS TRACK OF USERS WHO ACCESSED THE DATABASE-----------BEGIN for rec IN (SELECT username, action_name, TO_CHAR(TIMESTAMP, 'Mon-DD HH24:MI') LOGON, TO_CHAR(logoff_time, 'Mon-DD HH24:MI') LOGOFF, priv_used, comment_text from dba_audit_trail) LOOP DBMS_OUTPUT.put_line('user: ' || rec.username); DBMS_OUTPUT.put_line('Action: ' || rec.action_name); DBMS_OUTPUT.put_line('Logon: ' || rec.LOGON); DBMS_OUTPUT.put_line('Logoff: ' || rec.LOGOFF); DBMS_OUTPUT.put_line('priv_used: ' || rec.priv_used); DBMS_OUTPUT.put_line('comments: ' || rec.comment_text); DBMS_OUTPUT.put_line ('-------------------------------END of Record--------------------'); END LOOP; END; anonymous block completed BEGIN FOR rec IN (SELECT audit_type, db_user, object_schema, object_name, extended_timestamp, sql_text from dba_common_audit_trail) LOOP DBMS_OUTPUT.put_line( 'Audit Type: ' || rec.audit_type); DBMS_OUTPUT.put_line( 'User: ' || rec.db_user); DBMS_OUTPUT.put_line('What: ' || rec.object_schema ||'.' || rec.object_name); DBMS_OUTPUT.put_line('When: ' || rec.extended_timestamp); DBMS_OUTPUT.put_line('HOW: ' || rec.sql_text); DBMS_OUTPUT.put_line ('--------------------End Of Record--------------------'); END LOOP; END; 77
  78. 78. anonymous block completed /* Audit was created after the views has been created*/ AUDIT AUDIT AUDIT AUDIT AUDIT AUDIT AUDIT AUDIT AUDIT AUDIT AUDIT AUDIT AUDIT AUDIT AUDIT AUDIT AUDIT AUDIT AUDIT AUDIT AUDIT AUDIT SELECT, INSERT, UPDATE, DELETE ON EMPLOYEE BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON HRRECORD BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON CUSTOMER BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON PRODUCT BY ACCESS; SELECT,INSERT, UPDATE, DELETE ON INVENTORY BY ACCESS; SELECT,INSERT, UPDATE, DELETE ON TRANSHISTORY BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON SALES BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON ORDERS2 BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON CUSTOMERDATA BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON rCUSTOMERDATA BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON rorders BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON orders2 BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON EMPLOYEERV BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON EmployeeHR BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON PROJECTS BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON PROJECTWORKBOOK BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON PROJECT BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON PJWORK BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON CustCard BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON CARDCLOSE BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON customercards BY ACCESS; SELECT, INSERT, UPDATE, DELETE ON customercardsclose BY ACCESS; select, INSERT, succeeded. select, INSERT, succeeded. select, INSERT, succeeded. select, INSERT, succeeded. select,insert, UPDATE, succeeded. select,insert, UPDATE, succeeded. select, INSERT, succeeded. select, INSERT, succeeded. select, INSERT, succeeded. select, INSERT, succeeded. select, INSERT, succeeded. select, INSERT, succeeded. select, INSERT, succeeded. select, INSERT, succeeded. select, INSERT, succeeded. select, INSERT, succeeded. select, INSERT, succeeded. select, INSERT, succeeded. select, INSERT, succeeded. select, INSERT, succeeded. select, INSERT, succeeded. select, INSERT, succeeded. VIRTUAL PRIVATE DATABASE 78
  79. 79. SQL> SQL> SQL> 2 3 4 5 6 7 8 9 CREATE OR REPLACE FUNCTION EMPID_RET( p_schema IN VARCHAR2 DEFAULT NULL, p_object IN VARCHAR2 DEFAULT NULL) RETURN VARCHAR2 AS BEGIN RETURN 'EMPID = SYS_CONTEXT (''EMPLOYE_SEC'',''EMPID'')'; END; / Function created. SQL> SQL> /*Allows employee to view all the projects they have worked*/ Function created. SQL> SQL> 2 3 4 5 6 7 8 9 10 BEGIN DBMS_RLS.add_policy (object_schema => 'SYSTEM', OBJECT_NAME => 'projworkbook', POLICY_NAME => 'WORKBOOKPJ', FUNCTION_SCHEMA => 'SYSTEM', POLICY_FUNCTION => 'EMPID_RET', STATEMENT_TYPES => ' SELECT'); END; / DYNAMIC VIEWS > create or replace view EmployeeRV AS SELECT FIRST_NAME, MIDDLE_NAME, LAST_NAME, BIRTH_DATE, GENDER, EMPLOYEE_ID, MARITAL_STATUS, ADDRESS, CITY, STATE, POSTAL_CODE, PHONE FROM EMPLOYEE WHERE EMPLOYEE_ID = SYS_CONTEXT ('EMPLOYE_SEC','EMPID') view EMPLOYEERV created. > CREATE OR REPLACE TRIGGER DELUPD_RESTRICT_EMPLY BEFORE DELETE OR UPDATE ON EMPLOYEE FOR EACH ROW BEGIN IF(:OLD.EMPLOYEE_ID != SYS_CONTEXT ('EMPLOYE_SEC','EMPID')) THEN raise_application_error 79
  80. 80. (-20001, CHR(10) || '** YOU CAN ONLY UPDATE YOUR OWN RECORD.' || CHR(10) ||'** YOUR EMPLOYEE ID IS' || SYS_CONTEXT ('EMPLOYE_SEC','EMPID') ) ; END IF; END; TRIGGER DELUPD_RESTRICT_EMPLY compiled > CREATE or replace view EmployeeHR AS SELECT E.FIRST_NAME ,E.MIDDLE_NAME ,E.LAST_NAME , H.SICK_HOURS, H.VACATION_HOURS, H.RANK, H.HIRE_DATE, H.PAY_RATE, H.OFFICE_PHONE, D.NAME, G.FIRST_NAME||','||G.LAST_NAME AS "MANAGER_NAME" FROM EMPLOYEE E INNER JOIN HRRECORD H ON E.EMPLOYEE_ID = H.EMPLOYEE_ID INNER JOIN DEPARTMENT D ON H.DEPARTMENT_ID = D.DEPARTMENT_ID INNER JOIN EMPLOYEE G ON D.MANAGER_ID = G.EMPLOYEE_ID WHERE E.EMPLOYEE_ID = SYS_CONTEXT ('EMPLOYE_SEC','EMPID') view EMPLOYEEHR created. NON-DYNAMIC VIEWS SQL> 2 3 4 5 6 7 8 9 10 11 CREATE VIEW CUSTOMERINFO AS SELECT A.ACCOUNT_NUMBER, A.CUSTOMER_ID, A.STATUS, C.FIRST_NAME, C.MIDDLE_NAME, C.LAST_NAME, C.ADDRESS, C.CITY, C.PHONE, C.STATE, C.BIRTH_DATE FROM CUSTOMERCARDS A INNER JOIN CUSTOMER C ON A.CUSTOMER_ID = C.CUSTOMER_ID / View created. SQL> Create view empdirectory 2 as 80
  81. 81. 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 SELECT E.FIRST_NAME ||'-'||E.MIDDLE_NAME||','|| E.LAST_NAME AS EMPLOYEE, H.RANK, D.NAME AS "DEPARTMENT NAME", G.FIRST_NAME ||','||G.LAST_NAME AS "DEPARTMENT MANAGER" FROM EMPLOYEE E INNER JOIN HRRECORD H ON E.EMPLOYEE_ID = H.EMPLOYEE_ID INNER JOIN DEPARTMENT D ON H.DEPARTMENT_ID = D.DEPARTMENT_ID INNER JOIN EMPLOYEE G ON G.EMPLOYEE_ID = D.MANAGER_ID ORDER BY D.DEPARTMENT_ID; View created. SQL> create view orders2 2 as 3 SELECT C.FIRST_NAME ,C.MIDDLE_NAME,C.LAST_NAME ,C.CUSTOMER_ID, 4 S.ORDER_ID, S.PRODUCT_ID, P.PRODUCT_NAME AS "NAME", S.QTY_ORDERED, S.PRODUCT_PRICE_ORIGINAL AS "Orginal-Price", 5 S.TAX_AMOUNT_CHARGED AS "Tax", S.FREIGHT_AMOUNT_CHARGED AS "Shipping", S.TOTAL_AMOUNT AS "Final Amount", 6 S.ORDER_DATE AS "Date-Ordered" 7 from 8 SALES S 9 INNER JOIN CUSTOMER C 10 ON S.CUSTOMER_ID = C.CUSTOMER_ID 11 INNER JOIN 12 PRODUCT P 13 ON S.PRODUCT_ID = P.PRODUCT_ID; View created. SQL> 2 3 4 5 6 CREATE VIEW CUSTOMERDATA AS SELECT c.customer_Id ,C.FIRST_NAME, C.MIDDLE_NAME, C.LAST_NAME, C.ADDRESS, C.CITY, C.PHONE, C.STATE, C.BIRTH_DATE FROM CUSTOMER C; View created. SQL> 2 3 4 5 6 7 CREATE VIEW DEPARTMENTS AS SELECT E.FIRST_NAME ||','|| E.LAST_NAME AS MANAGER, D.NAME, H.OFFICE_PHONE FROM EMPLOYEE E INNER JOIN DEPARTMENT D ON 81
  82. 82. 8 9 10 11 12 SQL> SQL> 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 E.EMPLOYEE_ID = D.MANAGER_ID INNER JOIN HRRECORD H ON H.EMPLOYEE_ID = E.EMPLOYEE_ID; create view projworkbook as select e.first_name , e.middle_name, e.last_name,d.name as department_name, p.hours_assign, p.role, j.project_title as Project_Tile, start_date, j.end_date,e.first_name||','||e.last_name as "Project Manager" from employee e inner join hrrecord h on h.employee_id = e.employee_id inner join department d on h.department_id = d.department_id inner join projects j on j.manager_id = e.employee_id inner join projectworkbook p on j.project_id = p.project_id; View created. create or replace view rorders as SELECT C.CUSTOMER_ID, S.ORDER_ID, S.PRODUCT_ID, P.PRODUCT_NAME AS "NAME", S.QTY_ORDERED, S.PRODUCT_PRICE_ORIGINAL AS "Orginal-Price", S.TAX_AMOUNT_CHARGED AS "Tax", S.FREIGHT_AMOUNT_CHARGED AS "Shipping", S.TOTAL_AMOUNT AS "Final Amount", S.ORDER_DATE AS "Date-Ordered" from SALES S INNER JOIN CUSTOMER C ON S.CUSTOMER_ID = C.CUSTOMER_ID INNER JOIN PRODUCT P ON S.PRODUCT_ID = P.PRODUCT_ID; view RORDERS created. CREATE or replace VIEW rCUSTOMERDATA AS SELECT c.customer_Id, C.CITY, C.STATE, C.BIRTH_DATE, C.POSTAL_CODE, C.COUNTRY, C.GENDER, C.YEARLY_INCOME, C.MARITAL_STATUS , C.EDUCATIONAL_BACKGROUND ,C.TOTAL_CHILDREN ,C.TOTAL_CARS_OWNED,C.PROFESSION FROM CUSTOMER C; 82
  83. 83. view RCUSTOMERDATA created. View created. SQL> set echo off SQL> spool off; DATABASE MANAGEMENT > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION TO AlexHD TO BrendaUDH TO BerryHK TO DavidMGI TO EricYMU TO SamarawickramaULP TO RaymondPLK TO AckermanJKP TO RounthwaiteUHG TO LiGeorgeTRW TO MichaelsThVY TO AnnetteHiJ TO NiswongerOIU TO MohamedB2B TO RandallcythIK TO MohansuOK TO IvoLKW TO kaneVMP TO ThierrydherLK TO PhilipsCLZ TO caoJuIY 83
  84. 84. GRANT succeeded. > GRANT CREATE SESSION TO fordjeffNK GRANT succeeded. > GRANT CREATE SESSION TO STADICKDL GRANT succeeded. > GRANT CREATE SESSION TO DAVYALOVSKY0 GRANT succeeded. > show errors No Errors. > Create ROLE HR role HR created. > Grant select, update , insert on HRRECORD to HR Grant succeeded. > Create or replace public synonym employee for employee public synonym EMPLOYEE created. > Grant SELECT , INSERT, UPDATE on employee to HR Grant succeeded. > Grant HR TO MohansuOK Grant succeeded. > CREATE ROLE ACCOUNTANTS role ACCOUNTANTS created. > CREATE OR REPLACE PUBLIC SYNONYM TRANSACTIONS FOR TRANSHISTORY public synonym TRANSACTIONS created. > CREATE OR REPLACE PUBLIC SYNONYM SALES FOR SALES public synonym SALES created. > CREATE OR REPLACE PUBLIC SYNONYM ORDER1 FOR ORDERS2 public synonym ORDER1 created. > CREATE OR REPLACE PUBLIC SYNONYM CUSTDATA01 FOR CUSTOMERDATA public synonym CUSTDATA01 created. > GRANT SELECT, UPDATE ON TRANSACTIONS TO ACCOUNTANTS GRANT succeeded. > GRANT SELECT, UPDATE ON SALES TO ACCOUNTANTS GRANT succeeded. > GRANT SELECT, UPDATE ON ORDER1 TO ACCOUNTANTS GRANT succeeded. > GRANT SELECT ON CUSTDATA01 TO ACCOUNTANTS GRANT succeeded. > GRANT ACCOUNTANTS TO AckermanJKP GRANT succeeded. > GRANT ACCOUNTANTS TO RaymondPLK GRANT succeeded. > GRANT ACCOUNTANTS TO kaneVMP GRANT succeeded. > CREATE ROLE RANALYST role RANALYST created. > CREATE OR REPLACE PUBLIC SYNONYM CUSTDATA02 FOR rCUSTOMERDATA public synonym CUSTDATA02 created. > GRANT SELECT ON CUSTDATA02 TO RANALYST GRANT succeeded. > CREATE OR REPLACE PUBLIC SYNONYM ORDERS04 FOR rorders public synonym ORDERS04 created. > GRANT SELECT ON ORDERS04 TO RANALYST GRANT succeeded. > Grant RANALYST to DavidMGI Grant succeeded. 84
  85. 85. > CREATE ROLE SALES role SALES created. > GRANT SELECT ON TRANSACTIONS TO SALES GRANT succeeded. > GRANT SELECT ON SALES TO SALES GRANT succeeded. > GRANT SELECT ON ORDER1 TO SALES GRANT succeeded. > GRANT SELECT ON CUSTDATA01 TO SALES GRANT succeeded. > CREATE OR REPLACE PUBLIC SYNONYM PRODT FOR PRODUCT public synonym PRODT created. > GRANT SELECT, UPDATE, INSERT ON PRODT TO SALES GRANT succeeded. > CREATE OR REPLACE PUBLIC SYNONYM INVENT FOR INVENTORY public synonym INVENT created. > CREATE OR REPLACE PUBLIC SYNONYM INVENT FOR INVENTORY; GRANT SELECT, UPDATE(PRODUCT_ID, NEXT_STACK_DATE, QTY_REMANING), INSERT ON INVENT TO SALES; GRANT succeeded. > GRANT SALES TO MohamedB2B GRANT succeeded. > GRANT SALES TO ThierrydherLK GRANT succeeded. > CREATE ROLE CUSTOMERREP role CUSTOMERREP created. > CREATE OR REPLACE PUBLIC SYNONYM CUSTINFO FOR CUSTOMERINFO public synonym CUSTINFO created. > GRANT SELECT, INSERT, UPDATE ON CUSTINFO TO CUSTOMERREP GRANT succeeded. > CREATE OR REPLACE PUBLIC SYNONYM orders08 FOR orders2 public synonym ORDERS08 created. > GRANT SELECT, UPDATE ON orders08 to customerrep GRANT succeeded. > GRANT CUSTOMERREP TO NiswongerOIU GRANT succeeded. > GRANT CUSTOMERREP TO PhilipsCLZ GRANT succeeded. > CREATE ROLE EMPLOYEE role EMPLOYEE created. > /*EMPLOYEE DYNAMIC AND NON DYNAMIC VIEWS*/ > CREATE OR REPLACE PUBLIC SYNONYM EMPLOYEERV FOR EMPLOYEERV public synonym EMPLOYEERV created. > GRANT SELECT, UPDATE, INSERT ON EMPLOYEERV TO EMPLOYEE GRANT succeeded. > CREATE OR REPLACE PUBLIC SYNONYM EmployeeHR FOR EmployeeHR public synonym EMPLOYEEHR created. > GRANT SELECT, UPDATE, INSERT ON EmployeeHR TO EMPLOYEE GRANT succeeded. > CREATE OR REPLACE PUBLIC SYNONYM EMPDIRECTORY FOR empdirectory public synonym EMPDIRECTORY created. > GRANT SELECT ON EMPDIRECTORY TO EMPLOYEE GRANT succeeded. > CREATE OR REPLACE PUBLIC SYNONYM WORKBOOK FOR projworkbook public synonym WORKBOOK created. > GRANT EMPLOYEE TO AlexHD GRANT succeeded. > GRANT EMPLOYEE TO BerryHK GRANT succeeded. 85
  86. 86. > GRANT EMPLOYEE TO DavidMGI GRANT succeeded. > GRANT EMPLOYEE TO EricYMU GRANT succeeded. > GRANT EMPLOYEE To SamarawickramaULP GRANT succeeded. > GRANT EMPLOYEE TO RaymondPLK GRANT succeeded. > GRANT EMPLOYEE TO AckermanJKP GRANT succeeded. > GRANT EMPLOYEE TO RounthwaiteUHG GRANT succeeded. > GRANT EMPLOYEE TO MichaelsThVY GRANT succeeded. > GRANT EMPLOYEE TO AnnetteHiJ GRANT succeeded. > GRANT EMPLOYEE TO NiswongerOIU GRANT succeeded. > GRANT EMPLOYEE TO RandallcythIK GRANT succeeded. > GRANT EMPLOYEE TO MohamedB2B GRANT succeeded. > GRANT EMPLOYEE TO MohansuOK GRANT succeeded. > GRANT EMPLOYEE TO IvoLKW GRANT succeeded. > GRANT EMPLOYEE TO kaneVMP GRANT succeeded. > GRANT EMPLOYEE TO ThierrydherLK GRANT succeeded. > GRANT EMPLOYEE TO PhilipsCLZ GRANT succeeded. > GRANT EMPLOYEE TO caoJuIY GRANT succeeded. > GRANT EMPLOYEE TO fordjeffNK GRANT succeeded. > GRANT EMPLOYEE TO StadickDL GRANT succeeded. > GRANT EMPLOYEE TO DAVYALOVSKY0 GRANT succeeded. > GRANT EMPLOYEE TO BrendaUDH GRANT succeeded. > CREATE ROLE PJM role PJM created. > CREATE OR REPLACE PUBLIC SYNONYM PROJECT FOR PROJECTS public synonym PROJECT created. > CREATE OR REPLACE PUBLIC SYNONYM PJWORK FOR PROJECTWORKBOOK public synonym PJWORK created. > GRANT SELECT, INSERT, UPDATE ON PROJECT TO PJM GRANT succeeded. > GRANT SELECT , INSERT, UPDATE ON PJWORK TO PJM GRANT succeeded. > GRANT PJM TO StadickDL GRANT succeeded. > GRANT PJM TO AnnetteHiJ create or replace GRANT succeeded. public synonym invtuser for inventory_usr1; 86
  87. 87. grant select on invtuser to sales; GRANT succeeded. GRANT succeeded. > show errors No Errors. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. > GRANT CREATE SESSION GRANT succeeded. TO AlexHD TO BrendaUDH TO BerryHK TO DavidMGI TO EricYMU TO SamarawickramaULP TO RaymondPLK TO AckermanJKP TO RounthwaiteUHG TO LiGeorgeTRW TO MichaelsThVY TO AnnetteHiJ TO NiswongerOIU TO MohamedB2B TO RandallcythIK TO MohansuOK TO IvoLKW TO kaneVMP TO ThierrydherLK TO PhilipsCLZ TO caoJuIY TO fordjeffNK 87
  88. 88. > GRANT CREATE SESSION TO STADICKDL GRANT succeeded. > GRANT CREATE SESSION TO DAVYALOVSKY0 GRANT succeeded. > show errors No Errors. 88
  89. 89. QUALITY ASSURANCE 89
  90. 90. DATABASE DIAGRAM 90
  91. 91. DATABASE DICTIONARY SELECT TABLE_NAME, CONSTRAINT_NAME, CONSTRAINT_TYPE, DELETE_RULE,STATUS, INDEX_NAME FROM USER_CONSTRAINTS WHERE TABLE_NAME ='PRODUCT' OR TABLE_NAME = 'EMPLOYEE' OR TABLE_NAME = 'DEPARTMENT' OR TABLE_NAME = 'HRRECORD' OR TABLE_NAME = 'CUSTOMER' OR TABLE_NAME = 'sales' OR TABLE_NAME =' TRANSHISTORY' OR TABLE_NAME = 'INVENTORY' OR TABLE_NAME = 'PROJECTS' OR TABLE_NAME = 'PROJECTOWKRBOOK' OR TABLE_NAME = 'CUSTOMERCARDS' OR TABLE_NAME = 'Customercardsclose' OR TABLE_NAME = ' uemp' ORDER BY TABLE_NAME; TABLE_NAME -----------------------------CUSTOMER CUSTOMER CUSTOMER CUSTOMER CUSTOMER CUSTOMER CUSTOMER CUSTOMER CUSTOMER CUSTOMER CUSTOMER CUSTOMERCARDS CUSTOMERCARDS CUSTOMERCARDS CUSTOMERCARDS DEPARTMENT DEPARTMENT DEPARTMENT DEPARTMENT EMPLOYEE EMPLOYEE EMPLOYEE EMPLOYEE EMPLOYEE EMPLOYEE EMPLOYEE EMPLOYEE EMPLOYEE EMPLOYEE EMPLOYEE EMPLOYEE EMPLOYEE HRRECORD HRRECORD HRRECORD HRRECORD INVENTORY INVENTORY INVENTORY INVENTORY PRODUCT PRODUCT PRODUCT PRODUCT PRODUCT PROJECTS PROJECTS PROJECTS CONSTRAINT_NAME -----------------------------CUSTO_CUSTID_PK CUST_FIRSTNAME_NN CUST_MIDNAME_NN CUST_LASTNAME_NN CUST_BIRTHDATE_NN CUST__PHONE_NN CUST_ADDRESS_NN CUST_CITY_NN CUST_STATE_NN CUST_POSTALCODE_NN CUST_GENDER_NN CUSTCARDS_PK CUSTCARD_SER_UK CUSTCARDS_CUSTID_FK CUSTCARDS_EMPID_FK DEPTART_MANGID_FK DEPART_DEPARTSTRID_PK DEPT_NAME_NN DEPT_DEPARTID_NN EMPL_POSTALCODE_NN EMPL_NATIONALID_NN EMPL_PHONE_NN EMPL_STATE_NN EMPL_CITY_NN EMPL_ADDRESS_NN EMPL_GENDER_NN EMPL_LASTNAME_NN EMPL_BIRTHDATE_NN EMPL_MIDNAME_NN EMPL_FNAME_NN EMPLOYEEID_PK EMP_CUSTID_FK HRREC_EMPLOYEEID_FK HRREC_HRDEPTID_FK HRREC_EMPHIRIDUK_UK HRREC_EMPHRID_PK INVENTORY_INVID_PK INVENT_PRODID_FK INVENT_EMPID_FK INVENT_INVID_UK PROD_PRODUCTID_PK PROD_PRODCATEGORY_NN PROD_PRODNUMBER_NN PROD_PRODNAME_NN PROD_PRODCOST_NN PROJECT_PROJID_UK PROJECT_MAGID_FK PROJECT_PROJ_PK CONSTRAINT_TYPE --------------P C C C C C C C C C C P U R R R P C C C C C C C C C C C C C P R R R U P P R R U P C C C C U R P DELETE_RULE STATUS ----------- -------ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED NO ACTION ENABLED NO ACTION ENABLED NO ACTION ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED NO ACTION ENABLED CASCADE ENABLED CASCADE ENABLED ENABLED ENABLED ENABLED NO ACTION ENABLED NO ACTION ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED ENABLED NO ACTION ENABLED ENABLED INDEX_NAME -----------------------------CUSTO_CUSTID_PK CUSTCARDS_PK CUSTCARD_SER_UK DEPART_DEPARTSTRID_PK EMPLOYEEID_PK HRREC_EMPHIRIDUK_UK HRREC_EMPHRID_PK INVENTORY_INVID_PK INVENT_INVID_UK PROD_PRODUCTID_PK PROJECT_PROJID_UK PROJECT_PROJ_PK 48 rows selected SELECT CONSTRAINT_NAME, CONSTRAINT_TYPE, TABLE_NAME, SEARCH_CONDITION FROM USER_CONSTRAINTS WHERE TABLE_NAME ='PRODUCT' OR TABLE_NAME = 'EMPLOYEE' OR TABLE_NAME = 'DEPARTMENT' OR TABLE_NAME = 'HRRECORD' OR TABLE_NAME = 'CUSTOMER' OR TABLE_NAME = 'SALES ' OR TABLE_NAME ='TRANSHISTORY' OR TABLE_NAME = 'INVENTORY' OR TABLE_NAME = 'PROJECTS' OR TABLE_NAME = 'PROJECTOWKRBOOK' OR TABLE_NAME = 'CUSTOMERCARDS' OR TABLE_NAME = 'Customercardsclose'OR TABLE_NAME = 'uemp' ORDER BY TABLE_NAME; CONSTRAINT_NAME -----------------------------CUSTO_CUSTID_PK CUST_FIRSTNAME_NN CUST_MIDNAME_NN CUST_LASTNAME_NN CUST_BIRTHDATE_NN CUST__PHONE_NN CUST_ADDRESS_NN CUST_CITY_NN CUST_STATE_NN CUST_POSTALCODE_NN CUST_GENDER_NN CUSTCARDS_PK CUSTCARD_SER_UK CUSTCARDS_CUSTID_FK CUSTCARDS_EMPID_FK DEPTART_MANGID_FK DEPART_DEPARTSTRID_PK DEPT_NAME_NN DEPT_DEPARTID_NN EMPL_POSTALCODE_NN EMPL_NATIONALID_NN EMPL_PHONE_NN CONSTRAINT_TYPE --------------P C C C C C C C C C C P U R R R P C C C C C TABLE_NAME -----------------------------CUSTOMER CUSTOMER CUSTOMER CUSTOMER CUSTOMER CUSTOMER CUSTOMER CUSTOMER CUSTOMER CUSTOMER CUSTOMER CUSTOMERCARDS CUSTOMERCARDS CUSTOMERCARDS CUSTOMERCARDS DEPARTMENT DEPARTMENT DEPARTMENT DEPARTMENT EMPLOYEE EMPLOYEE EMPLOYEE SEARCH_CONDITION -------------------------------------------------------------------------------"FIRST_NAME" IS NOT NULL "MIDDLE_NAME" IS NOT NULL "LAST_NAME" IS NOT NULL "BIRTH_DATE" IS NOT NULL "PHONE" IS NOT NULL "ADDRESS" IS NOT NULL "CITY" IS NOT NULL "STATE" IS NOT NULL "POSTAL_CODE" IS NOT NULL "GENDER" IS NOT NULL "NAME" IS NOT NULL "DEPARTMENT_ID" IS NOT NULL "POSTAL_CODE" IS NOT NULL "NATIONAL_ID" IS NOT NULL "PHONE" IS NOT NULL 91
  92. 92. EMPL_STATE_NN EMPL_CITY_NN EMPL_ADDRESS_NN EMPL_GENDER_NN EMPL_LASTNAME_NN EMPL_BIRTHDATE_NN EMPL_MIDNAME_NN EMPL_FNAME_NN EMPLOYEEID_PK EMP_CUSTID_FK HRREC_EMPLOYEEID_FK HRREC_HRDEPTID_FK HRREC_EMPHIRIDUK_UK HRREC_EMPHRID_PK INVENTORY_INVID_PK INVENT_PRODID_FK INVENT_EMPID_FK INVENT_INVID_UK PROD_PRODUCTID_PK PROD_PRODCATEGORY_NN PROD_PRODNUMBER_NN PROD_PRODNAME_NN PROD_PRODCOST_NN PROJECT_PROJID_UK PROJECT_MAGID_FK PROJECT_PROJ_PK C C C C C C C C P R R R U P P R R U P C C C C U R P EMPLOYEE EMPLOYEE EMPLOYEE EMPLOYEE EMPLOYEE EMPLOYEE EMPLOYEE EMPLOYEE EMPLOYEE EMPLOYEE HRRECORD HRRECORD HRRECORD HRRECORD INVENTORY INVENTORY INVENTORY INVENTORY PRODUCT PRODUCT PRODUCT PRODUCT PRODUCT PROJECTS PROJECTS PROJECTS "STATE" IS NOT NULL "CITY" IS NOT NULL "ADDRESS" IS NOT NULL "GENDER" IS NOT NULL "LAST_NAME" IS NOT NULL "BIRTH_DATE" IS NOT NULL "MIDDLE_NAME" IS NOT NULL "FIRST_NAME" IS NOT NULL "PRODUCT_CATEGORY" IS NOT NULL "PRODUCT_ID" IS NOT NULL "PRODUCT_NAME" IS NOT NULL "PRODUCT_PRICE" IS NOT NULL 48 rows selected SELECT TRIGGER_NAME, table_name , TRIGGER_TYPE, TRIGGERING_EVENT, TABLE_NAME, COLUMN_NAME, REFERENCING_NAMES, DESCRiPTION, ACTION_TYPE, status , base_object_type FROM USER_TRIGGERS; trigg_fn.txt SELECT * FROM USER_PROCEDURES; proced.txt SELECT * from user_tab_privs where grantee IN( 'RANALYST', 'ACCOUNTANTS', 'SALES' ,'CUSOMERREP','HR', 'EMPLOYEE', 'DB') ORDER BY grantee; GRANTEE GRANTABLE HIERARCHY OWNER TABLE_NAME GRANTOR PRIVILEGE ------------------------------ ------------------------------ ------------------------------ ------------------------------ --------------------------------------- --------- --------ACCOUNTANTS NO NO SYSTEM CUSTOMERCARDSCLOSE SYSTEM SELECT ACCOUNTANTS NO NO SYSTEM SALES SYSTEM SELECT ACCOUNTANTS NO NO SYSTEM SALES SYSTEM UPDATE ACCOUNTANTS NO NO SYSTEM ORDERS2 SYSTEM SELECT ACCOUNTANTS NO NO SYSTEM ORDERS2 SYSTEM UPDATE ACCOUNTANTS NO NO SYSTEM CUSTOMERDATA SYSTEM SELECT ACCOUNTANTS NO NO SYSTEM TRANSHISTORY SYSTEM UPDATE ACCOUNTANTS NO NO SYSTEM TRANSHISTORY SYSTEM SELECT ACCOUNTANTS NO NO SYSTEM CUSTOMERCARDS SYSTEM SELECT ACCOUNTANTS NO NO SYSTEM CUSTOMERCARDS SYSTEM INSERT DB NO SYSTEM UEMP SYSTEM INSERT SYSTEM UEMP SYSTEM SELECT SYSTEM UEMP SYSTEM UPDATE SYSTEM EMPLOYEERV SYSTEM SELECT SYSTEM EMPLOYEEHR SYSTEM SELECT NO DB NO NO DB NO NO EMPLOYEE NO NO EMPLOYEE NO NO 92
  93. 93. EMPLOYEE NO SYSTEM EMPDIRECTORY SYSTEM SELECT SYSTEM EMPLOYEERV SYSTEM UPDATE SYSTEM EMPLOYEEHR SYSTEM UPDATE SYSTEM EMPLOYEEHR SYSTEM INSERT SYSTEM EMPLOYEERV SYSTEM INSERT SYSTEM EMPLOYEE SYSTEM INSERT SYSTEM HRRECORD SYSTEM INSERT SYSTEM HRRECORD SYSTEM SELECT SYSTEM HRRECORD SYSTEM UPDATE SYSTEM EMPLOYEE SYSTEM SELECT SYSTEM EMPLOYEE SYSTEM UPDATE SYSTEM RORDERS SYSTEM SELECT SYSTEM RCUSTOMERDATA SYSTEM SELECT SYSTEM CUSTOMERDATA SYSTEM SELECT SYSTEM INVENTORY_USR1 SYSTEM SELECT SYSTEM INVENTORY SYSTEM INSERT SYSTEM INVENTORY SYSTEM SELECT SYSTEM INVENTORY SYSTEM UPDATE SYSTEM PRODUCT SYSTEM INSERT SYSTEM PRODUCT SYSTEM SELECT SYSTEM PRODUCT SYSTEM UPDATE SYSTEM ORDERS2 SYSTEM SELECT SYSTEM TRANSHISTORY SYSTEM SELECT SYSTEM SALES SYSTEM SELECT NO EMPLOYEE NO NO EMPLOYEE NO NO EMPLOYEE NO NO EMPLOYEE NO NO HR NO NO HR NO NO HR NO NO HR NO NO HR NO NO HR NO NO RANALYST NO NO RANALYST NO NO SALES NO NO SALES NO NO SALES NO NO SALES NO NO SALES NO NO SALES NO NO SALES NO NO SALES NO NO SALES NO NO SALES NO NO SALES NO NO 39 rows selected DESC CUSTOMER Name ---------------------CUSTOMER_ID FIRST_NAME MIDDLE_NAME LAST_NAME GENDER BIRTH_DATE YEARLY_INCOME TOTAL_CHILDREN TOTAL_CARS_OWNED MARITAL_STATUS PROFESSION ADDRESS CITY STATE POSTAL_CODE COUNTRY PHONE EDUCATIONAL_BACKGROUND Null -------NOT NULL NOT NULL NOT NULL NOT NULL NOT NULL NOT NULL NOT NOT NOT NOT NULL NULL NULL NULL NOT NULL Type -----------NUMBER VARCHAR2(35) VARCHAR2(35) VARCHAR2(35) CHAR(15) VARCHAR2(45) NUMBER NUMBER NUMBER VARCHAR2(35) VARCHAR2(34) VARCHAR2(50) VARCHAR2(20) CHAR(35) VARCHAR2(20) VARCHAR2(35) VARCHAR2(25) VARCHAR2(35) DESC customercards Name Null Type -------------- -------- -------- 93
  94. 94. ACCOUNT_NUMBER NOT NULL CHAR(45) CUSTOMER_ID NOT NULL NUMBER PRINT_DATE DATE STATUS CHAR(20) EMPLOYEE_ID NOT NULL NUMBER DESC customercardsclose Name Null ----------------- -------SERIAL_NUMBER NOT NULL ACCOUNT_NUMBER NOT NULL CLOSE_EMPLOYEE_ID NOT NULL CLOSE_DATE NOTES CUSTOMER_ID DESC employee Name -------------EMPLOYEE_ID FIRST_NAME MIDDLE_NAME LAST_NAME BIRTH_DATE GENDER MARITAL_STATUS ADDRESS CITY STATE POSTAL_CODE PHONE NATIONAL_ID CUSTOMER_ID DESC hrrecord Name -------------EMPLOYEE_ID HR_ID DEPARTMENT_ID SICK_HOURS VACATION_HOURS RANK HIRE_DATE PAY_RATE OFFICE_PHONE Null -------NOT NULL NOT NULL NOT NULL NOT NULL NOT NULL NOT NULL NOT NOT NOT NOT NOT NOT NULL NULL NULL NULL NULL NULL Null -------NOT NULL NOT NULL NOT NULL DESC DEPARTMENT Name Null ------------- -------DEPARTMENT_ID NOT NULL NAME NOT NULL MANAGER_ID DESC SALES Name ---------------------CUSTOMER_ID TRANSACTON_ID PRODUCT_ID ORDER_ID QTY_ORDERED PRODUCT_PRICE_ORIGINAL PRODUCT_PRICE_WT_QTY TAX_AMOUNT_CHARGED FREIGHT_AMOUNT_CHARGED TOTAL_AMOUNT ORDER_DATE DESC inventory Name --------------INVENTORY_ID EMPLOYEE_ID PRODUCT_ID QTY_STOCKED QTY_REMANING STACK_DATE NEXT_STACK_DATE STORAGE_DATE Type -----------NUMBER VARCHAR2(30) VARCHAR2(30) VARCHAR2(30) VARCHAR2(45) CHAR(15) CHAR(20) VARCHAR2(50) VARCHAR2(35) VARCHAR2(35) VARCHAR2(20) VARCHAR2(25) NUMBER NUMBER Type -----------NUMBER NUMBER NUMBER NUMBER NUMBER VARCHAR2(45) CHAR(45) NUMBER VARCHAR2(35) Type -----------NUMBER VARCHAR2(40) NUMBER Null -------NOT NULL NOT NULL NOT NULL NOT NULL DESC TRANSHISTORY Name Null -------------- -------TRANSACTON_ID NOT NULL CREDIT_CARD_ID CARD_TYPE EXP_DATE TRANS_DATE AMOUNT_CHARGED BRAND DESC product Name ------------------PRODUCT_ID PRODUCT_NAME PRODUCT_PRICE PRODUCT_BRAND PRODUCT_DESCRIPTION PRODUCT_CATEGORY Type -------NUMBER CHAR(45) NUMBER DATE CLOB NUMBER Type -----------NUMBER VARCHAR2(60) NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER DATE Type -----------VARCHAR2(60) NUMBER CHAR(24) DATE DATE NUMBER CHAR(20) Null -------NOT NULL NOT NULL NOT NULL Type -----------NUMBER VARCHAR2(90) NUMBER VARCHAR2(35) CLOB NOT NULL VARCHAR2(30) Null -------NOT NULL NOT NULL NOT NULL Type -------NUMBER NUMBER NUMBER NUMBER NUMBER DATE DATE CHAR(40) 94

×