Database Project
Project Title:- Computer Company management information system
Team Members:-
Name Department Section
1. محمد علي عبد الحميد خسكية CS 4
2. محمد مبروك معوض محمد CS 4
3. محمود احمد ابراهيم شواره CS 4
4.
5.
Project Description:-
Computer Company management information system used to convert
paper documentation to computer documentation in a computers
company that buy PCs , laptops , keyboards , scanners …
And this company have many suppliers and employees
Normalization
Tables after 1NF:-
Tables after 2NF:-
Tables after 3NF:-
Entity Relationship Diagram
Mapping
Create Commands for each table
/* ------ Job Table ------- */
Create table job(
Job_id number (6),
job_name varchar2 (100) ,
salary number(5),
bouns number(6,3),
Constraint job_id_cons primary key(job_id),
Constraint salary_cons check(salary>0),
constraint bouns_cons check(bouns >=0 ),
constraint job_name_cons check(job_name is not null )
);
/* ------ employee Table ------- */
Create table employee(
Emp_id number(6),
Emp_fname varchar2 (100) ,
Emp_lname varchar2(100) ,
Emp_date date ,
Phone char(15) ,
Job_id number(6) ,
Constraint emp_id_cons primary key(Emp_id),
constraint job_id_fcons foreign key(Job_id ) references job (job_id) ON DELETE SET
NULL,
constraint emp_fname_cons check(emp_fname is not null ),
constraint emp_lname_cons check(emp_lname is not null ),
constraint emp_date_cons check(emp_date is not null ),
constraint emp_phone_cons check(phone is not null )
);
/* ------ Customers Table ------- */
Create table customer(
cust_id number(6) ,
cust_fname varchar2 (100) ,
cust_lname varchar2(100) ,
Phone char(15) ,
cust_address varchar2(100) ,
e_mail varchar2(50) ,
Constraint cust_id_cons primary key(cust_id),
Constraint e_mail_like_cons check(e_mail like '___%@___%.__%' ),
Constraint e_mail_un_cons unique(e_mail ),
constraint cust_fname_cons check(cust_fname is not null ),
constraint cust_lname_cons check(cust_lname is not null ),
constraint cust_phone_cons check(phone is not null ),
constraint cust_address_cons check(cust_address is not null ));
/* ------ Orders Table ------- */
Create table orders(
order_id number(6) ,
order_date date ,
cust_id number(6) ,
emp_id number(6) ,
Constraint order_id_cons primary key(order_id),
constraint cust_id_fcons foreign key (cust_id) references customer(cust_id) ON
DELETE SET NULL,
constraint emp_id_fcons foreign key (emp_id) references employee (emp_id) ON
DELETE SET NULL,
constraint order_date_cons check(order_date is not null )
);
/* ------ supplier Table ------- */
Create table supplier(
sup_id number(6) ,
sup_name varchar2 (100) ,
Phone char(15) ,
sup_address varchar2(100),
e_mail varchar2(50) ,
constraint sup_id_cons primary key (sup_id),
Constraint sup_mail_like_cons check(e_mail like '___%@___%.__%' ),
Constraint sup_mail_un_cons unique(e_mail ),
constraint sup_name_cons check(sup_name is not null ),
constraint sup_phone_cons check(phone is not null ),
constraint sup_address_cons check(sup_address is not null )
);
/* ------ store_item Table ------- */
Create table store_item(
item_id number(6) ,
item_name varchar2 (100) ,
item_price number(6) ,
available_amount number(4) ,
item_description varchar2(300) ,
sup_id number(6) ,
constraint item_id_cons primary key(item_id),
constraint item_name_cons check(item_name is not null ),
constraint item_price_cons check(item_price is not null ),
constraint available_amount_cons check (available_amount >= 0),
constraint sup_id_fcons foreign key (sup_id) references supplier(sup_id) ON DELETE SET
NULL);
/* ------ selled_item Table ------- */
Create table selled_item(
item_id number(6) ,
order_id number(6) ,
item_quantity number(4),
constraint com_prim primary key(item_id , order_id) ,
constraint order_prim foreign key (order_id) references orders(order_id) ON DELETE
SET NULL ,
constraint item_prim foreign key (item_id) references store_item(item_id) ON DELETE
SET NULL ,
constraint item_q_cons check(item_quantity is not null )
);
Insert Commands for each table
/* -------- job -------- */
insert into job values (3,'salesMan',2500,100);
insert into job values (4,'salesMan',2000,50);
/* -------- employee -------- */
insert into employee values(2,'ahmed','kamal','01-Jan-11',0116584788,3);
insert into employee values(4,'ali','sayed','5-Nov-11',0128584628,4);
/* -------- customer -------- */
insert into customer values(5,'mohamed','ahmed',01276399758,'41 st elhoria naser
sity','
[email protected]');
insert into customer values(6,'kamal','saed',01227676864,'52 st gerant
Alex','
[email protected]');
insert into customer values(14,'ahmed','ali',01287477854,'10 st elbhr
tanta','
[email protected]');
insert into customer values(19,'amina','mohamed',0126988745,'13 st moheb
tanta','
[email protected]');
/* -------- orders -------- */
insert into orders values (1,'11-Nov-14',5,2);
insert into orders values (2,'12-Nov-14',6,4);
insert into orders values (6,'5-Jan-15',14,2);
insert into orders values (7,'8-Jan-15',19,4);
/* -------- supplier -------- */
insert into supplier values (1,'Alshrouk',01284569875,'32 st Egypt
tanta','
[email protected]');
insert into supplier values (5,'alahram',01221478558,'40 st gov
shebin','
[email protected]');
insert into supplier values (6,'alaml',01165969487,'45 st gamaleldin
elsadat','
[email protected]');
/* -------- store_item -------- */
insert into store_item values(3,'labtob',3000,5,'DELL 4GiGa ram 1 tera ',1);
insert into store_item values(5,'Mouse',80,8,'Laser',5);
insert into store_item values(4,'Keyboard',70,4,'qwert',6);
insert into store_item values(6,'pc',2000,12,'Hp 50GIGa ram',1);
insert into store_item values(8,'scanner',800,4,'High Quality',6);
insert into store_item values(1,'PowerSupplier',300,4,'High Performance',6);
/* -------- selled_item -------- */
insert into selled_item values (3,1,1);
insert into selled_item values (5,1,3);
insert into selled_item values (4,1,5);
insert into selled_item values (6,1,2);
insert into selled_item values (3,2,2);
insert into selled_item values (8,2,1);
insert into selled_item values (5,2,5);
insert into selled_item values (4,6,5);
insert into selled_item values (1,7,1);
Index commands (at least two)
1- CREATE INDEX item_sup ON store_item (sup_id);
2- CREATE INDEX emp_job ON employee(job_id);
View commands (at least three views)
1–
create view orders_price
as
select se.order_id , st.item_price ,st.item_name , se.item_quantity ,
se.item_quantity *st.item_price total_item_price
from selled_item se
natural join store_item st
order by order_id ;
2–
create view customer_order
As
Select concat(concat(cu.cust_fname , ' ') , cu.cust_lname) cust_name,
concat(concat(em.emp_fname , ' ') , em.emp_lname) emp_name ,
orders_price .item_name ,
orders_price .item_price , orders_price .item_quantity ,
orders_price.total_item_price
from customer cu natural join employee em , orders_price ;
3–
create view Item_Suppliers
as
select ITEM_NAME, SUP_NAME ,PHONE,SUP_ADDRESS
from store_item natural join supplier
4–
create view History
as
select ORDER_DATE ,
CUST_FNAME ||' '||CUST_LNAME as "Customer Name" ,
EMP_FNAME ||' '||EMP_LNAME as "Employee Name" ,
ITEM_NAME,ITEM_QUANTITY,ITEM_PRICE,
ITEM_PRICE*ITEM_QUANTITY TotalPrice
from orders,customer,employee,store_item,selled_item
where orders.CUST_ID = customer.CUST_ID and
orders.EMP_ID = employee.EMP_ID and
orders.ORDER_ID = selled_item.ORDER_ID and
selled_item.ITEM_ID= store_item.ITEM_ID
order by ORDER_DATE
Procedures Commands (at least three procedures)
1-
Create or replace procedure upsalary(id IN number, sal IN number)
Is
neg EXCEPTION;
lrg EXCEPTION;
PRAGMA EXCEPTION_INIT(neg,-02290);
PRAGMA EXCEPTION_INIT(lrg,-01438);
Begin
update job set salary=sal where job_id=id;
exception when neg then
DBMS_outPUT.PUT_LINE('you can not update salary to negative
value');
when lrg then DBMS_outPUT.PUT_LINE('error it is very larg value');
End;
2-
create or replace procedure delete_cust(id in customer.cust_id%type)
Is
Begin
Delete from customer
Where cust_id=id;
Exception
When no_data_found then
Dbms_output.put_line('customer not found');
When others then
Dbms_output.put_line('customer not found');
End;
3-
create or replace procedure income (
Odate in nvarchar2 )
--history .ORDER_DATE%type
is
x number(5);
d varchar2(3);
-- User Define Exeption
invaledDate EXCEPTION;
DateNotInDB EXCEPTION;
begin
d := checkMydate(Odate);
if (d ='NO') then RAISE invaledDate;
end if;
select sum(TOTALPRICE) into x
from history where ORDER_DATE=Odate ;
if x>0 then
dbms_output.put_line('The Income in '|| Odate || ' Is ' ||x);
else
RAISE DateNotInDB ;
end if;
EXCEPTION
When no_data_found then
Dbms_output.put_line('No date fount');
when DateNotInDB then
dbms_output.put_line('There is no dataFount in '|| Odate );
when invaledDate then
dbms_output.put_line('You Must Enter A Valid Date ');
When others then
Dbms_output.put_line('Error');
Functions Commands (at least three functions)
1-
Create or replace function order_price(id IN orders_price.order_id%type)
return number
Is
s number;
Begin
select sum(total_item_price) into s
from orders_price
where order_id=id;
return s;
End;
2-
create or replace function emp_salary(id In employee.emp_id%type , name out
employee.emp_fname%type , jopname out jop.jop_name%type )
Return number
Is
Total_salary numer ;
Begin
Select concat(concat(em.emp_fname , ' ') , em.emp_lname) ,
(jo.salary+jo.bouns) , jo.jop_name into name , total_salary , jopname
From employee em natural join jop jo
Where emp_id=id;
Return total_salary;
Exception
When no_data_found then
Dbms_output.put_line('customer not found');
When others then
Dbms_output.put_line('customer not found');
End;
3-
CREATE OR REPLACE
FUNCTION checkMydate(checkDate IN VARCHAR2)
RETURN VARCHAR2
IS
v_result VARCHAR2(3);
v_date DATE;
BEGIN
v_date := to_date(checkDate,'dd-mm-yy');
V_RESULT := 'YES';
RETURN V_RESULT;
EXCEPTION WHEN OTHERS THEN
V_RESULT := 'NO';
RETURN v_result;
END;
4- loggin Function
create or replace function FN (
p1 in users.USER_ID%type,
p2 in users.PASS%type
) return number
is
c1 users.USER_ID%type;
x number;
begin
select USER_ID into c1 from users
where PASS =p2;
if c1=p1 then
return 1;
else
return 0;
end if;
end;
Triggers Commands (at least three triggers)
1-
CREATE OR REPLACE TRIGGER display_salary_changes
BEFORE DELETE OR INSERT OR UPDATE ON jop
FOR EACH ROW
WHEN (new.jop_id > 0)
DECLARE
sal_diff number;
BEGIN
sal_diff := :NEW.salary - :OLD.salary;
dbms_output.put_line('Old salary: ' || :OLD.salary);
dbms_output.put_line('New salary: ' || :NEW.salary);
dbms_output.put_line('Salary difference: ' || sal_diff);
END;
--2 -Secure Triggers
/* --- JOb --- */ /* --- secure_supplier---- */
CREATE OR REPLACE TRIGGER secure_job CREATE OR REPLACE TRIGGER secure_supplier
BEFORE DELETE OR INSERT OR UPDATE ON job BEGIN BEFORE DELETE OR INSERT OR UPDATE ON supplier BEGIN
IF (TO_CHAR(SYSDATE,'DY') IN ('FRI')) THEN IF (TO_CHAR(SYSDATE,'DY') IN ('FRI')) THEN
RAISE_APPLICATION_ERROR(-20500, 'The System is Off in RAISE_APPLICATION_ERROR(-20500, 'The System is Off in
Friday '); Friday ');
END IF;END; END IF;
/* --- employee--- */ END;
CREATE OR REPLACE TRIGGER secure_employee
BEFORE DELETE OR INSERT OR UPDATE ON employee BEGIN /* --- secure_store_item---- */
IF (TO_CHAR(SYSDATE,'DY') IN ('FRI')) THEN CREATE OR REPLACE TRIGGER secure_store_item
RAISE_APPLICATION_ERROR(-20500, 'The System is Off in BEFORE DELETE OR INSERT OR UPDATE ON store_item
Friday '); BEGIN
END IF;END; IF (TO_CHAR(SYSDATE,'DY') IN ('FRI')) THEN
/* --- secure_customer ---- */ RAISE_APPLICATION_ERROR(-20500, 'The System is Off in
Friday ');
CREATE OR REPLACE TRIGGER secure_customer
END IF;
BEFORE DELETE OR INSERT OR UPDATE ON customer BEGIN
END;
IF (TO_CHAR(SYSDATE,'DY') IN ('FRI')) THEN
RAISE_APPLICATION_ERROR(-20500, 'The System is Off in
Friday ');
END IF;END; /* --- secure_selled_item---- */
/* --- secure_orders---- */ CREATE OR REPLACE TRIGGER secure_selled_item
CREATE OR REPLACE TRIGGER secure_orders BEFORE DELETE OR INSERT OR UPDATE ON selled_item
BEGIN
BEFORE DELETE OR INSERT OR UPDATE ON orders BEGIN
IF (TO_CHAR(SYSDATE,'DY') IN ('FRI')) THEN
IF (TO_CHAR(SYSDATE,'DY') IN ('FRI')) THEN
RAISE_APPLICATION_ERROR(-20500, 'The System is Off in
RAISE_APPLICATION_ERROR(-20500, 'The System is Off in Friday ');
Friday ');
END IF;
END IF;
END;
END;
create trigger insertonjob after insert on job
begin
dbms_output.put_line('record added successfully');
end;
Forms
Login form :
Home Form :
Form 1:
Form 2:
Form 3:
Form 4:
Form 5:
Form 6:
Form 7 :
Reports
Report 1:
Report 2:
Report 3 :
Report 4 :
Report 5 :