LAB 1-IT300correction

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

TUNIS BUSINESS SCHOOL

UNIVERSITY OF TUNIS

Introduction to ORACLE DBMS & Reminder on

DDL, DML & SQL Script


correction

Consider the following relational database designed to manage an


airline.

Relational schema:
Flight (noflight, citdep, citar, dep_h, dep_mn, ar_h, ar_mn, ch_days)

Pilot (nopilot, name, address, sal, comm, hir_date)

Device (codetype, nbplace, design)

Plane (noplane, #codetype, yearserv, name, nbhflights)

Assignation (#noflight, date_flight, #nopilot, #noplane, nbpassen)

DBM (IT 300) 1


TUNIS BUSINESS SCHOOL
UNIVERSITY OF TUNIS

Data Dictionary

Tables Columns Designation Type


noflight Flight number CHAR(6)
FLIGHT

citdep Departure city VARCHAR2(30)


citar Arrival city VARCHAR2(30)
dep_h Departure _ hour NUMBER(2)
dep_mn Departure _Minute NUMBER(2)
PILOT

nopilot Pilot number CHAR(4)


name Pilot name VARCHAR2(30)
address Address VARCHAR2(30)
sal Salary NUMBER(8,2)
comm commission NUMBER(8,2)
DEVICE

codetype Code type CHAR(3)


nbplace Number of places NUMBER(3)
design Design VARCHAR2(50)

noplane Plane number CHAR(4)


PLANE

type Type CHAR(3)


yearserv Year of commissioning NUMBER(4)
name Name VARCHAR2(50)
nbhflights Total flight hours NUMBER(8)
ASSIGNATION

flight Flight number CHAR(6)


date_flight Flight Date DATE
pilot Pilot number CHAR(4)
plane Plane number CHAR(4)
nbpassen
Number of passenger NUMBER(3)

Exercice1:

Create Relational tables using the DBMS ORACLE 11G.

1. The script to create and insert information:

/* create Tables */

DBM (IT 300) 2


TUNIS BUSINESS SCHOOL
UNIVERSITY OF TUNIS

/* flight */

CREATE TABLE flight(


noflight CHAR(6),
citdep VARCHAR2(30),
citar VARCHAR2(30),
dep_h NUMBER(2),
dep_mn NUMBER(2),
ar_h NUMBER(2),
ar_mn NUMBER(2),
ch_days NUMBER(1));

/* PILOT */

CREATE TABLE pilot(


nopilot CHAR(4),
name VARCHAR2(30),
address VARCHAR2(30),
SAL NUMBER(8,2),
comm NUMBER(8,2),
hir_date DATE);

/* Device */

CREATE TABLE device(


codetype CHAR(3),
nbplace NUMBER(3),
design VARCHAR2(50));

/* Plane*/

CREATE TABLE plane(


noplane CHAR(4),
type CHAR(3),
annserv NUMBER(4),

DBM (IT 300) 3


TUNIS BUSINESS SCHOOL
UNIVERSITY OF TUNIS

name VARCHAR2(50),
nbhflight NUMBER(8));

/* Assignation */

CREATE TABLE assignation(


flight CHAR(6),
date_flight DATE,
pilot CHAR(4),
plane CHAR(4),
nbpass NUMBER(3));

/* Add relational Constraints */

ALTER TABLE flight


ADD ( CONSTRAINT C1_flight PRIMARY KEY(noflight));

ALTER TABLE pilot


ADD ( CONSTRAINT C1_pilot PRIMARY KEY(nopilot));

ALTER TABLE device


ADD ( CONSTRAINT C1_dev PRIMARY KEY(codetype));

ALTER TABLE plane


ADD ( CONSTRAINT C1_plane PRIMARY KEY(noplane),
CONSTRAINT C2_plane FOREIGN KEY(type) REFERENCES
device(codetype));

ALTER TABLE assignation


ADD ( CONSTRAINT C1_assign PRIMARY KEY(flight,date_flight),
CONSTRAINT C2_assign FOREIGN KEY(flight)
REFERENCES flight(noflight),
CONSTRAINT C3_assign FOREIGN KEY(pilot) REFERENCES
pilot(nopilot),
CONSTRAINT C4_assign FOREIGN KEY(plane)
REFERENCES plane(noplane));

DBM (IT 300) 4


TUNIS BUSINESS SCHOOL
UNIVERSITY OF TUNIS

/* Add records */

/* Insert - Table flight*/


insert into flight (noflight,citdep,citar,dep_h,dep_mn,ar_h,ar_mn,ch_days)
values ('AF8810','PARIS','DJERBA',9,0,11,45,0);
insert into flight (noflight,citdep,citar,dep_h,dep_mn,ar_h,ar_mn,ch_days)
values ('AF8809','DJERBA','PARIS',12,45,15,40,0);
insert into flight (noflight,citdep,citar,dep_h,dep_mn,ar_h,ar_mn,ch_days)
values ('IW201','LYON','FORT DE FRANCE',9,45,15,25,0);
insert into flight (noflight,citdep,citar,dep_h,dep_mn,ar_h,ar_mn,ch_days)
values ('IW655','LA HAVANE','PARIS',19,55,12,35,1);
insert into flight (noflight,citdep,citar,dep_h,dep_mn,ar_h,ar_mn,ch_days)
values ('IW433','PARIS','ST-MARTIN',17,00,8,20,1);
insert into flight (noflight,citdep,citar,dep_h,dep_mn,ar_h,ar_mn,ch_days)
values ('IW924','SYDNEY','COLOMBO',17,25,22,30,0);
insert into flight (noflight,citdep,citar,dep_h,dep_mn,ar_h,ar_mn,ch_days)
values ('IT319','BORDEAUX','NICE',10,35,11,45,0);
insert into flight (noflight,citdep,citar,dep_h,dep_mn,ar_h,ar_mn,ch_days)
values ('AF3218','MARSEILLE','FRANCFORT',16,45,19,10,0);
insert into flight (noflight,citdep,citar,dep_h,dep_mn,ar_h,ar_mn,ch_days)
values ('AF3530','LYON','LONDRES',8,0,8,40,0);
insert into flight (noflight,citdep,citar,dep_h,dep_mn,ar_h,ar_mn,ch_days)
values ('AF3538','LYON','LONDRES',18,35,19,15,0);
insert into flight (noflight,citdep,citar,dep_h,dep_mn,ar_h,ar_mn,ch_days)
values ('AF3570','MARSEILLE','LONDRES',9,35,10,20,0);

/* Insert Table pilot */


insert into Pilot (nopilot,name,address,sal,comm,hir_date)
values ('1333','FEDOI','NANTES',24000.00,0.00,'15/3/93');
insert into Pilot (nopilot,name,address,sal,comm,hir_date)
values ('6589','DUVAL','PARIS',18600.00,5580.00,'12/3/92');
insert into Pilot (nopilot,name,address,sal,comm,hir_date)
values ('7100','MARTIN','LYON',15600.00,16000.00,'01/7/93');
insert into Pilot (nopilot,name,address,sal,comm,hir_date)
values ('3452','ANDRE','NICE',22670.00,null,'12/12/92');
insert into Pilot (nopilot,name,address,sal,comm,hir_date)
values ('3421','BERGER','REIMS',18700.00,null,'28/12/92');

DBM (IT 300) 5


TUNIS BUSINESS SCHOOL
UNIVERSITY OF TUNIS

insert into Pilot (nopilot,name,address,sal,comm,hir_date)


values ('6548','BARRE','LYON',22680.00,8600.00,'10/12/92');
insert into Pilot (nopilot,name,address,sal,comm,hir_date)
values ('1243','COLLET','PARIS',19000.00,0.00,'15/4/93');
insert into Pilot (nopilot,name,address,sal,comm,hir_date)
values ('5643','DELORME','PARIS',21850.00,9850.00,'01/7/92');
insert into Pilot (nopilot,name,address,sal,comm,hir_date)
values ('6723','MARTIN','ORSAY',23150.00,null,'15/7/93');
insert into Pilot (nopilot,name,address,sal,comm,hir_date)
values ('8843','GAUCHER','CACHAN',17600.00,null,'20/9/92');
insert into Pilot (nopilot,name,address,sal,comm,hir_date)
values ('3465','PIC','TOURIS',18650.00,null,'15/7/93');

/* Insert Table device*/


insert into device (codetype,nbplace,design)
values ('74E',150,'BOEING 747-400 COMBI');
insert into device (codetype,nbplace,design)
values ('AB3',180,'AIRBUS A300');
insert into device (codetype,nbplace,design)
values ('741',100,'BOEING 747-100');
insert into device (codetype,nbplace,design)
values ('SSC',80,'CONCORDE');
insert into device (codetype,nbplace,design)
values ('734',450,'BOEING 737-400');

/* Insert Table plane*/


insert into plane (noplane,annserv,name,nbhflight,type)
values ('8832',1988,'Paris',16000,'734');
insert into plane (noplane,annserv,name,nbhflight,type)
values ('8567',1988,'Reims',8000,'734');
insert into plane (noplane,annserv,name,nbhflight,type)
values ('8467',1995,'Sud',600,'734');
insert into plane (noplane,annserv,name,nbhflight,type)
values ('7693',1988,'Pacifique',34000,'741');
insert into plane (noplane,annserv,name,nbhflight,type)
values ('8556',1989,null,12000,'AB3');
insert into plane (noplane,annserv,name,nbhflight,type)

DBM (IT 300) 6


TUNIS BUSINESS SCHOOL
UNIVERSITY OF TUNIS

values ('8432',1991,'Malte',10600,'AB3');
insert into plane (noplane,annserv,name,nbhflight,type)
values ('8118',1992,null,11800,'74E');

/* Insert Table assignation */


insert into assignation (flight,date_flight,nbpass,pilot,plane)
values ('IW201','01/3/94',310,'6723','8567');
insert into assignation (flight,date_flight,nbpass,pilot,plane)
values ('IW201','02/3/94',265,'6723','8832');
insert into assignation (flight,date_flight,nbpass,pilot,plane)
values ('AF3218','12/6/94',83,'6723','7693');
insert into assignation (flight,date_flight,nbpass,pilot,plane)
values ('AF3530','12/11/94',178,'6723','8432');
insert into assignation (flight,date_flight,nbpass,pilot,plane)
values ('AF3530','13/12/94',156,'6723','8432');
insert into assignation (flight,date_flight,nbpass,pilot,plane)
values ('AF3538','21/12/94',110,'6723','8118');
insert into assignation (flight,date_flight,nbpass,pilot,plane)
values ('IW201','03/3/94',164,'1333','8567');
insert into assignation (flight,date_flight,nbpass,pilot,plane)
values ('AF8810','02/3/94',160,'7100','8556');
insert into assignation (flight,date_flight,nbpass,pilot,plane)
values ('IT319','02/3/94',105,'3452','8432');
insert into assignation (flight,date_flight,nbpass,pilot,plane)
values ('IW433','22/3/94',178,'3421','8556');
insert into assignation (flight,date_flight,nbpass,pilot,plane)
values ('IW655','23/3/94',118,'6548','8118');
insert into assignation (flight,date_flight,nbpass,pilot,plane)
values ('IW655','20/3/94',402,'1243','8467');
insert into assignation (flight,date_flight,nbpass,pilot,plane)
values ('IW655','18/1/94',198,'5643','8467');
insert into assignation (flight,date_flight,nbpass,pilot,plane)
values ('IW924','30/9/94',412,'8843','8832');
insert into assignation (flight,date_flight,nbpass,pilot,plane)
values ('IW201','01/8/94',156,'6548','8432');
insert into assignation (flight,date_flight,nbpass,pilot,plane)
values ('AF8810','02/9/94',88,'6589','7693');

DBM (IT 300) 7


TUNIS BUSINESS SCHOOL
UNIVERSITY OF TUNIS

insert into assignation (flight,date_flight,nbpass,pilot,plane)


values ('AF3218','02/9/94',98,'8843','7693');
insert into assignation (flight,date_flight,nbpass,pilot,plane)
values ('AF3570','12/9/94',56,'1243','7693');
1. Please copy paste the following script then execute it:

2 : Click on :


execute as script 1 : Copy paste here
the script

The output of the script

2. To show the structure of any table:


Describe table_name;
Desc table_name;
Example: describe filight;

3. To display the content of any table:

Select * from tale_name;

Example : select * from pilot;

DBM (IT 300) 8


TUNIS BUSINESS SCHOOL
UNIVERSITY OF TUNIS

4. To save your work for this instance ORACLE : commit;


5. To leave ORACLE: exit;

DBM (IT 300) 9

You might also like