You are on page 1of 23

Academy of Economic Studies

Faculty of Cybernetics, Statistics and Economic Informatics

Database Project
Hotel franchise database

Student:

Nistor Cosmin Dumitru


Group 1052, E series

Project theme
This database is created to give to the management
information about its customers , what hotel they often choose,
what services they use most often and which are the employees
who provide most services. With this information, the hotel
management can determine which are their best employees and
offer them primes, most requested services to increase the
number of employees who perform them and the most loyal
customers to offer them discounts and extra facilities.
The database is easy to use and the structure of the table
allows the user to easily obtain all this information.

Database description

The database is composed of 7 tables according to the next


conceptual scheme:

Relationship between the tables

One client can stay at more hotels and one hotel can have more
customers. To break the many-to-many relationship we create the
intersection entity named CLIENT.

One hotel can offer more services and one service can be offered by
more hotels. To break the many-to-many relationship we create the
intersection entity named SERVICES_CHECK.
One customer can request more services and one service can be
requested by more customers. To break the many-to-many relationship
we create the intersection entity named SERVING_CHECK.
One employee works at one hotel and one hotel can have more
employees.

One employee is specialized in offering only one service, and one


service can be offered by more employees.

Tables description

The HOTELS table contains information about hotels: name,address,


city,phone number.

CREATE TABLE HOTELS


(id_hotel NUMBER(3) CONSTRAINTS id_hotel_pk PRIMARY KEY,
name_hotel CHAR (30) CONSTRAINTS name_hotel_nn CHECK (name_hotel is
not NULL),
city CHAR(20) CONSTRAINT city_nn CHECK (city is not NULL),
adress_hotel CHAR(50) CONSTRAINTS adress_hotel_nn CHECK (adress_hotel
is not NULL),
phone_number CHAR(15) CONSTRAINTS phone_number_uq UNIQUE)

The CUSTOMERS table contains informations about customers: name,


phone number, email.

CREATE TABLE CUSTOMERS


(customer_id number(3) CONSTRAINTS customer_id_pk PRIMARY KEY,
customer_name CHAR(30) CONSTRAINTS customer_name_nn CHECK
(customer_name is not NULL),
phone_number(15) CONSTRAINTS phone_uq UNIQUE,
email CHAR(30) CONSTRAINT email_uq UNIQUE)

The EMPLOYEES table contains informations about the employees of


the hotels: name, phone number, number of solicitations and date of
employment, the hotel that he works for and the service he offers.

CREATE TABLE EMPLOYEES


(id_employee number(3) CONSTRAINTS id_employee_pk PRIMARY KEY,
id_hotel number(3) CONSTRAINTS id_hotel_fk REFERENCES HOTELS(id_hotel),
id_services number(3) CONSTRAINTS id_services_fk REFERENCES
SERVICES(id_service),
name CHAR(30) CONSTRAINTS namee_nn CHECK (name is not null),

phone_number number(15) CONSTRAINTS phone_numberb_uq UNIQUE,


date_employment DATE)

The SERVICES table contains informations about the avaible services:


name, description and price.

CREATE TABLE SERVICES


(id_service number(3) CONSTRAINTS id_service_pk PRIMARY KEY,
name_service char(20) CONSTRAINTS name_nn CHECK (name_service is not
null),
description_service VARCHAR2(30) CONSTRAINTS description_uq UNIQUE,
price number(6,2) CONSTRAINTS price_nn CHECK (price is not null))

The CLIENTS table is the intersection table that contains informations


about what customers check in at what hotels.

CREATE TABLE CLIENTS


(customer_id number(3) CONSTRAINTS customerr_id_fk REFERENCES
CUSTOMERS(customer_id),
id_hotel number(3) CONSTRAINTS id_hotelr_fk REFERENCES
HOTELS(id_hotel),
checkin_number number(5) CONSTRAINTS checkin_number_nn CHECK
(checkin_number is not null),
date_last_checkin DATE)

The SERVICES_CHECK table is the intersection table that offers


informations about what hotel offers what services.

CREATE TABLE SERVICES_CHECK


(id_service number(3) CONSTRAINTS id_service_fk REFERENCES
SERVICES(id_service),
id_hotel number(3) CONSTRAINTS id_hotels_fk REFERENCES
HOTELS(id_hotel),
offer_start DATE CONSTRAINTS offer_start_nn not null)

The SERVING_CHECK table is the intersection table that offers


informations about what client uses certain services.

CREATE TABLE SERVING_CHECK


(id_service number(3) CONSTRAINTS id_servicesb_fk REFERENCES
SERVICES(id_service),

customer_id number(3) CONSTRAINTS customer_id_fk REFERENCES


CUSTOMERS(customer_id),
utilisation_no char(10) CONSTRAINTS utilisation_no_nn not null)

Data definition language comands (CREATE, ALTER,


DROP)
1) --Add in the CUSTOMERS table a new attribute called residence_city
ALTER TABLE CUSTOMERS
ADD (residence_city VARCHAR(20))
2) --Create a new table HOTEL_STARS with the attributes id_hotel and
stars_no.
CREATE TABLE HOTEL_STARS
(id_hotel number(3) CONSTRAINTS id_hotelst_fk REFERENCES(id_hotel),
stars_no number(2) CONSTRAINTS stars_no_nn CHECK (stars_no is not null))
3) --Add in the HOTELS table the stars_no attribute
ALTER TABLE HOTELS
ADD(stars_no number (2))
4) --Delete the residence_city attribute
ALTER TABLE CUSTOMERS
DROP column residence_city
5) --Delete the HOTEL_STARS table
DROP TABLE HOTEL_STARS

6) --Add a null type constraint for the stars_no attribute from the HOTELS
table
ALTER TABLE HOTELS
ADD CONSTRAINT stars_no_nn CHECK (stars_no is not null)

7) --Modify the dimension of the attribute adress from table HOTELS from 40
to 50.
ALTER TABLE HOTELS
MODIFY adress_hotel VARCHAR2(50)

Data manipulation language


commands(INSERT,UPDATE,DELETE,SELECT)
Populating the HOTELS table using the INSERT command:
insert into HOTELS values(1, 'Phoenihia Majestic','Bucuresti','Splaiul
Independentei nr 102','0213245531',5)
insert into HOTELS values(2, 'Pheonihia Suits','Bucuresti','Bulevardul Dacia nr
4','0214567765',5)
insert into HOTELS values(3, 'Pheonihia Plaza','Bucuresti','Strada Vasile
Strambu nr 9','9213445687',4)
insert into HOTELS values(4, 'Pheonihia Resorts','Constanta','Strada Ion
Minculescu nr 2','0219998787',4)
insert into HOTELS values(5, 'Pheonihia Sibiu','Sibiu','Bulevardul Constitutiei
nr 21','0269211231',5)
insert into HOTELS values(6, 'Pheonihia Oradea','Oradea','Bulevardul Unirii nr
3','0278255231',3)
insert into HOTELS values(7, 'Pheonihia Brasov','Brasov','Strada Revolutiei nr
54','0298221413',4)
insert into HOTELS values(8, 'Pheonihia Pitesti','Pitesti','Bulevardul Aurel
Vlaicu nr 84','0256789890',4)
insert into HOTELS values(9, 'Pheonihia Nord','Oradea','Strada Victoriei nr
32','0213645758',4)
insert into HOTELS values(10, 'Pheonihia Palace','Sibiu','Strada Episcopiei nr
1-3','021898978',3)
insert into HOTELS values(11, 'Pheonihia Opera','Pitesti','Strada Cosma
Andrei nr 18','0215668943',3)
insert into HOTELS values(12, 'Pheonihia Novotel','Brasov','Calea Victoriei nr
2','0217995678',4)
insert into HOTELS values(13, 'Pheonihia Gott','Brasov','Strada Johann nr
2','0298765446',3)

insert into HOTELS values(14, 'Pheonicia Athene','Bucuresti','Bulevardul


Dacia nr 1-3','0219843423',5)

Populating the SERVICES table using the INSERT


command:
insert into SERVICES
insert into SERVICES
question',0)
insert into SERVICES
insert into SERVICES
insert into SERVICES
children',18)
insert into SERVICES
insert into SERVICES
insert into SERVICES
insert into SERVICES
entertainment',20)
insert into SERVICES
insert into SERVICES

values(1, 'Massage','Diverse type of massages', 12.3)


values(2, 'Reception','Answers the customers
values(3, 'Cleaning','Clothes cleaning',14)
values(4, 'Vault', 'Seifkeep goods for stay period', 9.5)
values(5, 'Child supervision','Taking care of the
values(6,
values(7,
values(8,
values(9,

'Alarm','Waking up customer on request',0)


'Room service','Food delivery in room',1.5)
'Car parking','Parking the customers car',4)
'Nonformal activities','Guest

values(10, 'Fitness','Acees to the hotels gym',7.8)


values(11, 'Pool','Acces to the hotels pool', 9)

Populating the CUSTOMERS table using the INSERT


command:
insert into CUSTOMERS values(1,'Nistor
Cosmin',0761709938,'nistorcosmind@gmail.com')
insert into CUSTOMERS values(2,'Ledu
Maria',0744202929,'ledum@gmail.com')
insert into CUSTOMERS values(3,'Mitran
George',0744202920,'mitrang@gmail.com')
insert into CUSTOMERS values(4,'Lica
Daniela',0744202927,'licad@gmail.com')
insert into CUSTOMERS values(5,'Petru
Maria',0743202926,'petrum@gmail.com')
insert into CUSTOMERS values(6,'Gologan
Ana',0753202925',gologana@gmail.com')
insert into CUSTOMERS values(7,'Georgescu
Lili',0743202924,'georgescul@gmail.com')

insert into CUSTOMERS values(8,'Merca


Mihai',0734202923,'mercam@gmail.com')
insert into CUSTOMERS values(9,'Lolev
Cristian',0764202922,'lolevc@gmail.com')
insert into CUSTOMERS values(10,'Sapera
Camelia',07323202921,'saperac@gmail.com')
insert into CUSTOMERS values(11,'Satni
Marius',0744202919,'satnim@gmail.com')
insert into CUSTOMERS values(12,'Raicu
Simona',0755202918,'raicus@gmail.com')
insert into CUSTOMERS values(13,'Tudose
Catalina',0754202917,'tudosec@gmail.com')
insert into CUSTOMERS values(14,'Garofil
Elena',0765202917,'garofile@gmail.com')
insert into CUSTOMERS values(15,'Matru
Marius',0763202916,'matrum@gmail.com')
insert into CUSTOMERS values(16,'Caranica
Ion',0754202915,'caranicai@gmail.com')
insert into CUSTOMERS values(17,'Tascu
Iulian',0755202914,'tascui@gmail.com')
insert into CUSTOMERS values(18,'Cucli
Alexandru',0754202913,'cuclia@gmail.com')
insert into CUSTOMERS values(19,'Cara
Nicolae',0734202912,'caran@gmail.com')
insert into CUSTOMERS values(20,'Stan
Daniel',0755202911,'stand@gmail.com')
insert into CUSTOMERS values(21,'Mincu
Andrei',0743202910,'mincua@gmail.com')
insert into CUSTOMERS values(22,'Palu
Adrian',0745202909,'palua@gmail.com')
insert into CUSTOMERS values(23,'Corsa
Victor',0764202908,'corsav@gmail.com')
insert into CUSTOMERS values(24,'Jimbote
Silviu',0761202907,'jimbotes@gmail.com')
insert into CUSTOMERS values(25,'Jambon
Andrei',0744202906,'jambona@gmail.com')

Populating the EMPLOYEES table using the INSERT


command:
insert into EMPLOYEES values(1,1,1,'Mihale
Aura','0799876756',TO_DATE('12.10.2002','DD.MM.YYYY'))
insert into EMPLOYEES values(2,2,1,'Pica
Ana',0799876751',TO_DATE('12.11.2012','DD.MM.YYYY'))
insert into EMPLOYEES values(3,1,3,'Covaci
Dan',0799876752',TO_DATE('13.01.2003','DD.MM.YYYY'))
insert into EMPLOYEES values(4,2,5,'Cara
Gigi','0799876753',TO_DATE('12.12.2010','DD.MM.YYYY'))
insert into EMPLOYEES values(5,3,7,'Mihali
Maria','0799876754',TO_DATE('14.01.2013','DD.MM.YYYY'))
insert into EMPLOYEES values(6,3,8,'Macra
Gina','0799876755',TO_DATE('14.05.2013','DD.MM.YYYY'))
insert into EMPLOYEES values(7,3,9,'Tuc
Maria','07998767757',TO_DATE('07.07.2007','DD.MM.YYYY'))
insert into EMPLOYEES values(8,3,4,'Costea
Nicola','0799876758',TO_DATE('04.06.2013','DD.MM.YYYY'))
insert into EMPLOYEES values(9,4,4,'Dima
Florin','0799876759',TO_DATE('08.08.2011','DD.MM.YYYY'))
insert into EMPLOYEES values(10,4,1,'Misu
George','0799876750',TO_DATE('09.09.2009','DD.MM.YYYY'))
insert into EMPLOYEES values(11,4,3,'Buji
Ana','0799876706',TO_DATE('19.04.2011','DD.MM.YYYY'))
insert into EMPLOYEES values(12,4,2,'Ghita
Andrei','0799876716',TO_DATE('13.04.2011','DD.MM.YYYY'))
insert into EMPLOYEES values(13,4,11,'Lica
Vasile','0799876726',TO_DATE('12.11.2011','DD.MM.YYYY'))

insert into EMPLOYEES values(14,5,3,'Mirdan


Mina','0799876736',TO_DATE('14.05.2011','DD.MM.YYYY'))
insert into EMPLOYEES values(15,5,5,'Jaso
Nela','0799876746',TO_DATE('11.11.2011','DD.MM.YYYY'))
insert into EMPLOYEES values(16,5,6,'Cale
Diana','0799876766',TO_DATE('02.02.2009','DD.MM.YYYY'))
insert into EMPLOYEES values(17,5,8,'Mare
Eliza','0729876756,TO_DATE('01.01.2014','DD.MM.YYYY'))
insert into EMPLOYEES values(18,7,9,'Alexa
Andra','0799876776',TO_DATE('13.07.2008','DD.MM.YYYY'))
insert into EMPLOYEES values(19,7,8,'Tataru
Iulian','0799876786',TO_DATE('14.08.2013','DD.MM.YYYY'))
insert into EMPLOYEES values(20,7,5,'Stoica
Alex','0799876796',TO_DATE('14.08.2013','DD.MM.YYYY'))
insert into EMPLOYEES values(21,7,2,'Stoica
Eugen',0799876056',TO_DATE('07.07.2011','DD.MM.YYYY'))
insert into EMPLOYEES values(22,7,1,'Spau
Simona',0799876156',TO_DATE('09.07.2013','DD.MM.YYYY'))
insert into EMPLOYEES values(23,8,1,'Anastase
Iustin','0799876256',TO_DATE('14.06.2012','DD.MM.YYYY'))
insert into EMPLOYEES values(24,8,2,'Cardi
Liviu','0799856356',TO_DATE('05.08.2010','DD.MM.YYYY'))
insert into EMPLOYEES values(25,8,3,'Holban
Alina','0799876456',TO_DATE('09.06.2011','DD.MM.YYYY'))
insert into EMPLOYEES values(26,6,4,'Holban
Miruna','0799876556',TO_DATE('02.04.2013','DD.MM.YYYY'))
insert into EMPLOYEES values(27,6,5,'Mostea
Vlad','0799876656',TO_DATE('12.05.2010','DD.MM.YYYY'))
insert into EMPLOYEES values(28,6,6,'Gudi
Maria','0719876756',TO_DATE('17.07.2010','DD.MM.YYYY'))
insert into EMPLOYEES values(29,9,7,'Lupu
Cornelia','0799876856',TO_DATE('08.11.2010','DD.MM.YYYY'))
insert into EMPLOYEES values(30,9,8,'Enache
Stela','0799870756',TO_DATE('21.01.2013','DD.MM.YYYY'))
insert into EMPLOYEES values(31,9,9,'Stan
George','0799871756',TO_DATE('19.09.2011','DD.MM.YYYY'))
insert into EMPLOYEES values(32,10,11,'Gali
Daniela','0799276756',TO_DATE('27.02.2013','DD.MM.YYYY'))
insert into EMPLOYEES values(33,10,1,'Anton
Petre','0799836756',TO_DATE('24.08.2011','DD.MM.YYYY'))

insert into EMPLOYEES values(34,10,2,'Caraiola


Dan','0799854756',TO_DATE('29.09.2013','DD.MM.YYYY'))
insert into EMPLOYEES values(35,11,3,'Mini
Diana','0799866756',TO_DATE('31.03.2013','DD.MM.YYYY'))
insert into EMPLOYEES values(36,11,5,'Geambz
Alin','0799886756',TO_DATE('30.10.2013','DD.MM.YYYY'))
insert into EMPLOYEES values(37,11,7,'Sima
Gigi','0799823566',TO_DATE('31.12.2013','DD.MM.YYYY'))
insert into EMPLOYEES values(38,14,8,'Stavre
Ana','0799876326',TO_DATE('22.04.2013','DD.MM.YYYY'))
insert into EMPLOYEES values(39,14,9,'Coada
Catalina','0799767532',TO_DATE('25.06.2011','DD.MM.YYYY'))
insert into EMPLOYEES values(40,14,10,'Coada
Stefan','0791176756',TO_DATE('06.04.2004','DD.MM.YYYY'))
insert into EMPLOYEES values(41,12,1,'Chiran
Monica','0799136756',TO_DATE('09.04.2013','DD.MM.YYYY'))
insert into EMPLOYEES values(42,12,2,'Patru
Costin','0799446756',TO_DATE('15.08.2012','DD.MM.YYYY'))
insert into EMPLOYEES values(43,12,4,'Pota
Silviu','0799346756',TO_DATE('31.07.2012','DD.MM.YYYY'))
insert into EMPLOYEES values(44,13,8,'Nurciu
Chirana','0799376756',TO_DATE('28.07.2011','DD.MM.YYYY'))
insert into EMPLOYEES values(45,13,7,'Ianusi
Georgiana','0799556756',TO_DATE('12.07.2007','DD.MM.YYYY'))
insert into EMPLOYEES values(46,13,10,'Costea
Bianca','0793376576',TO_DATE('08.08.2008','DD.MM.YYYY'))

Populating the CLIENTS table using the INSERT command:


insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(1,1,7, TO_DATE('30.12.2013','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(1,5,4, TO_DATE('14.04.2013','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(1,1,3, TO_DATE('15.01.2013','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(2,4,5, TO_DATE('13.02.2013','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(2,14,9, TO_DATE('25.03.2013','DD.MM.YYYY'))

insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)


values(3,11,22, TO_DATE('29.05.2013','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(3,12,33, TO_DATE('30.03.2013','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(4,13,4, TO_DATE('14.09.2012','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(4,12,3, TO_DATE('28.08.2012','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(5,11,4, TO_DATE('30.11.2011','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(5,3,5, TO_DATE('05.12.2010','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(6,4,6, TO_DATE('14.08.2013','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(6,5,9, TO_DATE('12.10.2011','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(7,6,8, TO_DATE('09.08.2011','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(7,7,7, TO_DATE('09.05.2012','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(8,8,9, TO_DATE('15.06.2012','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(8,9,20, TO_DATE('27.07.2011','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(9,10,10, TO_DATE('30.08.2010','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(10,11,13, TO_DATE('14.09.2013','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(11,12,15, TO_DATE('23.07.2013','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(12,13,17, TO_DATE('24.08.2013','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(13,14,27, TO_DATE('17.09.2011','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(16,1,8, TO_DATE('24.09.2010','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(15,3,9, TO_DATE('30.11.2011','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(16,3,6, TO_DATE('25.06.2011','DD.MM.YYYY'))

insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)


values(17,2,5, TO_DATE('14.12.2012','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(18,4,8, TO_DATE('30.01.2010','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(19,6,2, TO_DATE('02.02.2013','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(20,9,3, TO_DATE('24.04.2013','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(21,8,10, TO_DATE('02.01.2012','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(22,1,9, TO_DATE('03.03.2010','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(23,1,11, TO_DATE('03.02.2011','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(23,1,14, TO_DATE('03.04.2011','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(25,1,7, TO_DATE('05.04.2010','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(25,1,8, TO_DATE('06.06.2012','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(11,1,4, TO_DATE('17.07.2013','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(16,1,5, TO_DATE('18.09.2013','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(17,1,6, TO_DATE('25.10.2012','DD.MM.YYYY'))
insert into CLIENTS(customer_id,id_hotel,checkin_number,date_last_checkin)
values(19,1,7, TO_DATE('22.11.2011','DD.MM.YYYY'))

Populating the SERVING_CHECK table with the INSERT


command:
insert into SERVICES_CHECK(id_service,id_hotel,offer_start) values
(1,1,TO_DATE('22.11.2011','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start) values
(1,6,TO_DATE('01.01.2008','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start) values
(2,1,TO_DATE('02.01.2009','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start) values
(2,4,TO_DATE('03.02.2010','DD.MM.YYYY'))

insert into SERVICES_CHECK (id_service,id_hotel,offer_start)


(3,5,TO_DATE('04.03.2010','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(3,7,TO_DATE('02.02.2008','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(4,8,TO_DATE('03.03.2009','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(4,9,TO_DATE('14.04.2011','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(5,10,TO_DATE('15.04.2011','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(5,14,TO_DATE('06.05.2010','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(6,1,TO_DATE('07.05.2011','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(6,2,TO_DATE('08.07.2011','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(7,3,TO_DATE('07.07.2010','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(7,4,TO_DATE('09.08.2009','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(8,5,TO_DATE('11.08.2008','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(8,6,TO_DATE('12.09.2012','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(9,7,TO_DATE('15.09.2013','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(9,8,TO_DATE('05.10.2011','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(10,9,TO_DATE('23.10.2009','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(10,10,TO_DATE('02.11.2012','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(11,11,TO_DATE('01.12.2008','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(11,11,TO_DATE('23.12.2011','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(1,11,TO_DATE('04.01.2006','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(3,11,TO_DATE('07.01.2009','DD.MM.YYYY'))

values
values
values
values
values
values
values
values
values
values
values
values
values
values
values
values
values
values
values
values

insert into SERVICES_CHECK (id_service,id_hotel,offer_start)


(5,13,TO_DATE('09.04.2008','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(2,12,TO_DATE('22.02.2011','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(4,11,TO_DATE('09.07.2012','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(6,11,TO_DATE('03.08.2010','DD.MM.YYYY'))
insert into SERVICES_CHECK (id_service,id_hotel,offer_start)
(7,12,TO_DATE('04.06.2008','DD.MM.YYYY'))

values
values
values
values
values

Populating the SERVING_CHECK table with the INSERT


command:
insert into SERVING_CHECK(customer_id,
values(1,1,'4')
insert into SERVING_CHECK(customer_id,
values(1,2,'5')
insert into SERVING_CHECK(customer_id,
values(2,4,'6')
insert into SERVING_CHECK(customer_id,
values(2,3,'12')
insert into SERVING_CHECK(customer_id,
values(3,5,'7')
insert into SERVING_CHECK(customer_id,
values(3,6,'11')
insert into SERVING_CHECK(customer_id,
values(4,7,'2')
insert into SERVING_CHECK(customer_id,
values(4,8,'3')
insert into SERVING_CHECK(customer_id,
values(5,9,'9')
insert into SERVING_CHECK(customer_id,
values(5,10,'14')
insert into SERVING_CHECK(customer_id,
values(6,11,'23')
insert into SERVING_CHECK(customer_id,
values(6,1,'11')

id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)

insert into SERVING_CHECK(customer_id,


values(7,3,'17')
insert into SERVING_CHECK(customer_id,
values(7,5,'22')
insert into SERVING_CHECK(customer_id,
values(8,7,'25')
insert into SERVING_CHECK(customer_id,
values(8,9,'8')
insert into SERVING_CHECK(customer_id,
values(9,11,'9')
insert into SERVING_CHECK(customer_id,
values(9,2,'7')
insert into SERVING_CHECK(customer_id,
values(10,4,'23')
insert into SERVING_CHECK(customer_id,
values(10,6,'5')
insert into SERVING_CHECK(customer_id,
values(11,8,'6')
insert into SERVING_CHECK(customer_id,
values(11,10,'9')
insert into SERVING_CHECK(customer_id,
values(12,1,'7')
insert into SERVING_CHECK(customer_id,
values(12,4,'8')
insert into SERVING_CHECK(customer_id,
values(13,7,'11')
insert into SERVING_CHECK(customer_id,
values(13,10,'15')
insert into SERVING_CHECK(customer_id,
values(15,2,'14')
insert into SERVING_CHECK(customer_id,
values(15,5,'7')
insert into SERVING_CHECK(customer_id,
values(16,8,'9')
insert into SERVING_CHECK(customer_id,
values(16,11,'3')
insert into SERVING_CHECK(customer_id,
values(17,3,'6')
insert into SERVING_CHECK(customer_id,
values(17,6,'13')

id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)

insert into SERVING_CHECK(customer_id,


values(18,9,'12')
insert into SERVING_CHECK(customer_id,
values(18,1,'15')
insert into SERVING_CHECK(customer_id,
values(19,5,'10')
insert into SERVING_CHECK(customer_id,
values(19,9,'20')
insert into SERVING_CHECK(customer_id,
values(20,2,'24')
insert into SERVING_CHECK(customer_id,
values(20,6,'13')
insert into SERVING_CHECK(customer_id,
values(21,10,'15')
insert into SERVING_CHECK(customer_id,
values(21,3,'17')
insert into SERVING_CHECK(customer_id,
values(22,7,'7')
insert into SERVING_CHECK(customer_id,
values(22,11,'8')
insert into SERVING_CHECK(customer_id,
values(23,3,'10')
insert into SERVING_CHECK(customer_id,
values(23,5,'13')
insert into SERVING_CHECK(customer_id,
values(25,8,'21')
insert into SERVING_CHECK(customer_id,
values(25,7,'4')

id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)
id_service,utilisation_no)

Examples of interogations
Using aggregate functions, GROUP BY, HAVING
--Display the name of the customer who consumed services in

value of at least 250

select c.customer_name, sum(to_number(r.utilisation_no)*s.price)


from customers c, serving_check r, services s
where s.id_service=r.id_service and c.customer_id=r.customer_id
group by c.customer_name
having sum(to_number(r.utilisation_no)*s.price)>250

-- Display the name of the customers and the total number of services
solicitations if it was greater than 14
select c.customer_name, sum(to_number(r.utilisation_no)) as "Utilisation
times"
from customers c, serving_check r, services s
where s.id_service=r.id_service and c.customer_id=r.customer_id
group by c.customer_name
having sum(to_number(r.utilisation_no))>14

Using UNION, MINUS, INTERSECT


--Display the name of the clients which checked in in Sibiu and of
those checked in in Oradea using UNION operator
select c.customer_name
from customers c, hotels h, clients r
where c.customer_id=r.customer_id and r.id_hotel=h.id_hotel and
h.city='Sibiu'
union
select c.customer_name
from customers c, hotels h, clients r
where c.customer_id=r.customer_id and r.id_hotel=h.id_hotel and
h.city='Oradea'

--Display all the employees that work in Bucuresti except those

working at the Phoenihia Majestic hotel using the MINUS operator


select a.name
from employees a, hotels h
where a.id_hotel=h.id_hotel and city='Bucuresti'
minus
select a.name
from employees a, hotels h
where a.id_hotel=h.id_hotel and h.name_hotel='Pheonihia Majestic'

--Display using the INTERSECT operator the employees who work


in Brasov, at the Pheonihia Novotel
select a.name
from employees a, hotels h
where a.id_hotel=h.id_hotel and h.city='Brasov'
intersect
select a.name
from employees a, hotels h
where a.id_hotel=h.id_hotel and h.name_hotel='Pheonihia Novotel'

Using single row functions


--Display the name of the employees hired before 2008
select name, date_employment
from employees
where extract(year from date_employment)<2008

Using the CASE statement


--Increase the price of the Massage by 14%, the one of the vault
by 19%, the one of the Parking by 20% and the rest by 10%.

select name_service, (case when name_service='Massage' then 1.14


when name_service='Vault' then 1.19
when name_service='Parking' then 1.2
else 1.1
end)*price NewPriceA
from service

Constructing and manipulating other objects


of the database: views, indexes, synonyms
and sequences
--Create a virtual table to display the customers that used the
massage service, only to be viewed
create or replace view customers_serv
as
select c.customer_name, r.utilisation_no
from customers c, serving_check r, services s
where c.customer_id=r.customer_id and r.id_service=s.id_service and
s.name_service='Massage'
with read only

--Create an index on HOTELS table for the hotel name with the
purpose of facilitating the access to their names
create index index_hotel on hotels(name_hotel)

*delete it after
drop inder index_hotel

--Create a synonym for the CUSTOMERS table


create synonym hotel_customers for customers

*delete it after
drop synonym hotel_customers
--Create a sequence with a min value of 1 and max of 55

create sequence sequence_s


start with 1
increment by 1
maxvalue 55
nocycle
*delete it after
drop sequence sequence_s

Hierarchical queries (CONNECT BY, PRIOR,


LEVEL, SYS_CONNECT_BY_PATH)
--Create the HIERARCHY table with the attributes id_employee,
id_manager
CREATE TABLE HIERARCHY
(id_employee number(3) constraints id_employee_pl PRIMARY KEY,
name char(30),
id_manager number(3))

--Insert values in the HIERARCHY table


insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert

into
into
into
into
into
into
into
into
into
into
into
into
into

HIERARCHY
HIERARCHY
HIERARCHY
HIERARCHY
HIERARCHY
HIERARCHY
HIERARCHY
HIERARCHY
HIERARCHY
HIERARCHY
HIERARCHY
HIERARCHY
HIERARCHY

values(101,'Mihalcea Ana', NULL)


values(102,'Preda Alin',101)
values(103,'Popa Emilia',102)
values(104,'Musu Irina',103)
values(105,'Nicolae Alexandra', 102)
values(106,'Ghita Nicolae',103)
values(107,'Dima David',105)
values(108,'Rosca Bianca',107)
values(109,'Iliade Madalina',108)
values(110,'Stoian Andrei', 104)
values(111,'Chiaburu Alex',105)
values(112,'Farmache Ana',104)
values(113,'Predoiu Mihai',112)

--Display the employees subordinated to the root


select id_employee, name, id_manager

from HIERARCHY
connect by prior id_employee=id_manager
start with upper(name)='MIHALCEA ANA'
--Display all employees and specify for each employee the root,

number of superior and all his superiors


select name, conect_by_root name nume_manageri,
level-1 no_superiors, sys_connect_by_path(name,'-')name_superiors
from HIERARCHY
start with id_employee=101
connect by prior id_employee=id_manager;

--Display the employees subordinated to 102 in the organigram


select level, lpad('',level)|| Employee Name
from hierarchy
connect by prior id_employee=id_manager
start with id_manager=102
order by level;

You might also like