You are on page 1of 20

Kingdom of Saudi Arabia

Ministry of Education
Majmaah University
College of Computer and Information Sciences

project of " SuperMarket " management


Last phase "3"

Name
Raya alnwiser
Hind alhoqail
Razan alolah

ID

Email

Group
number
341203839 Rnase223@gmail.com
IT2
341205194 Power.330@hotmail.com
IT2
341203855 r.n.3777@hotmail.com
IT2

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

supermarket have six relationship between


Manger ,Customer, Seller, purchase ,employee and product <All this attributes
make it in tables have primary key ,foreign and relationship between them
also write SQL with Some tasks witch is perform in SQL such as "Select",
"Insert", "Update", "Delete", "Create", and "Drop" ,Application of aggregate
functions like "AVG" , "SUM", "COUNT" and Join etc.>

Goals that have been implemented :*To make buying things an easier process.
* To produce reports on overdue books.
* To check which products are currently available in the supermarket.
* For the employee to be able to obtain information of who has ordered
a particular product.
* To keep a record of customers and their details.
* To be able to add, edit or deleted details concerning the customers .
* For each customer to have a primary id in case two people have the
same name .
* For each product have a primary code.
* The system should only allow authorized people to the data.

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

1- Create an unnamed procedure :-

2- Create an Named procedure :-

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

3- Anchor data type :-

4- Create a synonym :-

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

5- Create an abstract data type (ADT) :-

6- Create a sequence:-

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

7- Use a decision control:-

8- Create a function :-

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

9- Create a view :-

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

10-Create an index:-

11-create a trigger :-

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

12-create cursor :-

Done

Conclusion
If some product has been ordered, and it takes a while for that product to
arrive, we do not want the same product ordered several days in a row.
The system must contain some sort of list of items on order.
As the items received come in, they should be taken off this list.
Last and not least This project gave us the opportunity to try our new
skills in practice. While doing this project we also gained deeper
understanding on database design and how it can be implemented in real
life situations.
We believe we can use our database designing skills also in other projects.
*If you want follow the SQL statement are here :-

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

FINALLY OUR SQL :CREATE TABLE MANGER (


M_ID number NOT NULL ,
M_NAME

VARCHAR2(20),

M_NUMBER number(10),
CONSTRAINT MNAMER_PK PRIMARY KEY (M_ID));
insert into manger(m_id , m_name,m_number)
values(2254,'razan',0987);
insert into manger(m_id , m_name,m_number)
values(2255,'hind',0970);
create view m_name as select manger.m_id, m_number from manger INNER JOIN saller on
manger.m_id = saller.m_id
where manger.m_name ='raya';
select*from manger ;

declare
idm NUMBER;
mname VARCHAR2(20);
begin
idm :='&enter_id_MANGER';
select M_NAME into mname
from MANGER
where M_ID=idm;

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

dbms_output.put_line('manger' ||idm|| 'is'||mname);


end;
/

create sequence seq_manger start with 1 increment by 1;


insert into manger(m_id,m_name)
values(234,'toto');
select seq_manger.nextval from daul;

alter table manger add check ( m_number >0);


select *from manger ;
create sequence seq_manger start with 1 increment by 1;
select * from manger ;
CREATE TABLE SALLER
(
S_ID

NUMBER NOT NULL,

S_MANE VARCHAR2 (20),


M_ID NUMBER NOT NULL ,
CONSTRAINT PK_SALLER PRIMARY KEY (S_ID),
CONSTRAINT FK_SALLER foreign KEY (M_ID) REFERENCES MANGER (M_ID) );
CREATE TABLE COSTOMER
(
C_ID NUMBER NOT NULL ,
C_NAME VARCHAR2 (20),

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

C_ACCAUNT NUMBER ,
S_ID NUMBER NOT NULL ,
PU_TRANSACTION_NO NUMBER ,
CONSTRAINT PK_COSTOMER PRIMARY KEY (C_ID));
ALTER TABLE COSTOMER ADD CONSTRAINT FK_COSTOMER foreign KEY(S_ID) REFERENCES SALLER
(S_ID) on delete cascade ;

alter table COSTOMER add constraint fk_PU_TRANSACTION_NO foreign key (PU_TRANSACTION_NO)


references PURCHASE_TABLE (PU_TRANSACTION_NO);
CREATE TABLE PURCHASE_TABLE
(
PU_TRANSACTION_NO number(9) NOT NULL,
PU_NAME VARCHAR2(20),
P_CODE number(10),
CONSTRAINT PURCHASE_PK PRIMARY KEY (PU_TRANSACTION_NO));
Alter table PURCHASE_TABLE ADD CONSTRAINT PURCHASE_FK foreign KEY(P_CODE) REFERENCES
PRODUCT (P_CODE);
CREATE TABLE EMPLOYEE
(
E_ID number(10)

NOT NULL,

E_TELEPHONE NUMBER(10),
E_ADDRESS VARCHAR2 (10),
E_MANE VARCHAR2 (20),
M_ID number not null,
S_ID number not null,

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

CONSTRAINT EMPLOYEE_PK PRIMARY KEY (E_ID),


CONSTRAINT FK_employee foreign KEY(M_ID)REFERENCES MANEGER_TABLE (M_ID));
alter table employee add CONSTRAINT EMPLOYEE_FK foreign KEY(S_ID)REFERENCES SALLER_TABLE
(S_ID);
CREATE SYNONYM EMP
FOR EMPLOYEE;
select * from EMP ;
CREATE TABLE PRODUCT
(
P_CODE number NOT NULL,
P_BRAND VARCHAR2(9),
E_ID number,
CONSTRAINT PK_PRODUCT PRIMARY KEY (P_CODE),
CONSTRAINT fk_PRODUCT foreign KEY(E_ID) REFERENCES EMPLOYEE(E_ID));

insert into PRODUCT (P_CODE, P_BRAND )


values(848,'apple');
insert into PRODUCT (P_CODE, P_BRAND )
values(430,'galxy');
insert into PRODUCT (P_CODE, P_BRAND )
values(84,'mac');
insert into PRODUCT (P_CODE, P_BRAND )
values(002,'cose');
insert into PRODUCT (P_CODE, P_BRAND )
values(54,'tshp');

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

select P_CODE, P_BRAND from PRODUCT ;

select COUNT (p_code) from PRODUCT ;


select sum (p_code) from PRODUCT ;
select avg (p_code) from PRODUCT ;

create sequence seq_PRODUCT start with 1 increment by 1;


insert into PRODUCT(p_code,p_brand)
values(234,'toto');
select seq_product.nextval from dual;
select seq_product.currval from dual;

set serveroutput on
begin
dbms_output.put_line ('hello,world!');
end;
/

create or replace procedure greetings


as begin dbms_output.put_line ('hello,world!');
end;
/
declare
code NUMBER;

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

BRAND VARCHAR2(9);
begin
code :='&enter_your_code';
select p_brand into BRAND
from PRODUCT
where p_code:=code;
dbms_output.put_line('PRODUCT' || code || 'is' ||'' || brand );
end;
/

CREATE TYPE PersonType AS OBJECT


(
p_code number,
P_BRAND VARCHAR2(9),
);

select*from PRODUCT;
set serveroutput on
declare
PCODE number ;
PBRAND number := 430;
begin
PCODE:='&enter_the_number_of_code';
if PCODE > PBRAND then

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

dbms_output.put_line('highest prand is'||PCODE||'prands');


else
dbms_output.put_line(' losest prand is '||PCODE||'prands');
end if;
end;
/
create or replace function Eidbonus(
p_code code.p_code%type
)
return decimal
is
bonus decimal(10,3);
begin
if(p_code is not null)
then
bonus:=pcode+800;
else
bouns:=p_code+10;
end if;
return bonus;
end;
/
create view p_code as select PRODUCT.p_code from PRODUCT INNER JOIN EMPLOYEE on
PRODUCT.e_id = EMPLOYEE.e_id
where product.p_code=848;

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

create index p_code on PRODUCT (p_brand);

create or replace trigger pcode


before insert
on product
for each row
declare
pbrand VARCHAR2(9),
begin
select user into pbrand
from dual;
end; /
set serveroutput on
declare cursor p_cursor is

select* from PRODUCT;


p_row product%rowtype;
begin
open p_cursor ;
loop
fetch p_cursor into p_row;
exit when p_cursor%notfound;
dbms_output.put_line(p_row.p_code||''||p_row.p_brand);

Kingdom of Saudi Arabia


Ministry of Education
Majmaah University
College of Computer and Information Sciences

end loop;
close p_cursor;
end;
/
create or replace trigger p_code before insert on product for each row
declare
pbrand VARCHAR2(9);
begin
select user into pbrand
from dual;
end;
/