You are on page 1of 24

DATABASE MANAGEMENT SYSTEMS

LAB CYCLE SHEET 2

SUBMITED BY
A DUHITHA HARSHA
19MIS0271

List the airplane id, type and company name.

List the airline for which fare is more than 3000.


List the airport names which are arrival ports for at least 3 flights.

Retrieve airport code that is greater than all airplane id of given airplane
type.
List the flight number that has no booking.

Retrieve the airline names that has at least two bookings.

Retrieve the airport code that are only arrival and not departure port .
Retrieve the flight numbers that arrive in all the cities of Tamilnadu.

Retrieve the country which has more than 10 airports.

Find the airline which has highest number of intermediate stoppings.


List the flight number, the departure airport for the first leg
of the flight, and the arrival airport for the last leg of the flight.

List the flight numbers and weekdays of all flights or flight legs that
depart from Pune Airport (airport code „PNQ‟) and
arrive in Los Angeles International Airport (airport code „LAX‟).

List the flight number, departure airport code, scheduled departure time,
arrival airport code, scheduled arrival time, and weekdays of all flights
or
flight legs that depart from some airport in the city of Karnataka and
arrive
at some airport in the city of Kerala.
List all fare information for flight number „CO197‟.

Retrieve the number of available seats for flight number „CO197‟ on


„30-nov-2016‟.
MISCELLANEOUS

Create an empty table myflight with same structure as flight table.

SQL> create table myflight as (select * from flight where 0=1); Tablecreated.

SQL> DESC MYFLIGHT


Name Null? Type

FLIGHT_NUMBER NOT NULL NUMBER(10)


AIRLINE VARCHAR2(40)
WEEKDAYS VARCHAR2(30)
Create a table fare with same contents as fare table.

SQL> create table fare1 as select flight_number "flight_number",amount


"amount",
FARE_CODE "FARE_CODE",RESTRICTION "RESTRICTION" FROM FARE;

Table created.

SQL> DESC

FARE1
Name Null? Type

flight_number NUMBER (9)


amount NUMBER (10,2)
FARE_CODE NUMBER (9)
RESTRICTION VARCHAR2 (25)

Create a table with flightno,legno,arrivalairportcode. Insert values


into this table from existing tables.

SQL> create table flight_leg1 as select flight_number "flight_number"


,leg_numbe
r"leg_number",arrival_airport_code "arrival_airport_code" from flight_leg; Table

created.

SQL> SELECT * FROM FLIGHT_LEG1;

flight_number leg_number arrival_airport_code

108 144 9999


127 133 8888
142 111 7777
442 155 6666
171 177 5555
3710 188 4444
6302 199 3333
18115 542 2222
5111 452 1000
852 432 1111

10 rows selected.
Create a virtual table that contains flightno,arrival airport name.

SQL> create view flight_leg2 as (select f.flight_number,a.name from flight_leg2

,airport a where f.arrival_airport_code=a.airport_code); View

created.

SQL> select * from flight_leg;

FLIGHT_NUMBER

LEG_NUMBER

SCHEDULED_DEPARTURE_TIM

DEPARTURE_AIRPORT_CODE ARRIVAL_AIRPORT_CODE

SCHEDULED_ARRIVAL_TIM

E108 144
12-JUN-00 11.11.13.000000 AM
1111 9999

12-JUN-00 12.12.00.000000 PM
FLIGHT_NUMBER LEG_NUMBER

SCHEDULED_DEPARTURE_TIME

DEPARTURE_AIRPORT_CODE

ARRIVAL_AIRPORT_CODE SCHEDULED_ARRIVAL_TIME

127 133
12-JUN-01 11.11.13.000000 AM
2222 8888
12-JUN-01 12.12.00.000000 PM

FLIGHT_NUMBER LEG_NUMBER

SCHEDULED_DEPARTURE_TIME

DEPARTURE_AIRPORT_CODE ARRIVAL_AIRPORT_CODE

SCHEDULED_ARRIVAL_TIME

142 111
12-JUN-02 10.11.13.000000 AM
3333 7777
12-JUN-02 12.12.00.000000 PM

FLIGHT_NUMBER LEG_NUMBER

SCHEDULED_DEPARTURE_TIME DEPARTURE_AIRPORT_CODE

ARRIVAL_AIRPORT_CODE

SCHEDULED_ARRIVAL_TIME

442 155
12-JUN-00 11.11.13.000000 AM
4444 6666
12-JUN-00 12.12.00.000000 PM
FLIGHT_NUMBER LEG_NUMBER

SCHEDULED_DEPARTURE_TIME

DEPARTURE_AIRPORT_CODE

ARRIVAL_AIRPORT_CODE SCHEDULED_ARRIVAL_TIME

171 177
12-JUN-03 10.11.13.000000 AM
5555 5555
12-JUN-03 12.12.00.000000 PM

FLIGHT_NUMBER LEG_NUMBER

SCHEDULED_DEPARTURE_TIME

DEPARTURE_AIRPORT_CODE

ARRIVAL_AIRPORT_CODE SCHEDULED_ARRIVAL_TIME

3710 188
12-JUN-04 11.11.13.000000 AM
6666 4444
12-JUN-04 12.12.00.000000 PM

FLIGHT_NUMBER LEG_NUMBER

SCHEDULED_DEPARTURE_TIME

DEPARTURE_AIRPORT_CODE

ARRIVAL_AIRPORT_CODE SCHEDULED_ARRIVAL_TIME

6302 199
12-JUN-05 10.11.13.000000 AM
7777 3333
12-JUN-05 12.12.00.000000 PM
FLIGHT_NUMBER LEG_NUMBER

SCHEDULED_DEPARTURE_TIME

DEPARTURE_AIRPORT_CODE ARRIVAL_AIRPORT_CODE
SCHEDULED_ARRIVAL_TIME

18115 542
12-APR-00 11.11.13.000000 AM
8888 2222
12-APR-00 12.12.00.000000 PM

FLIGHT_NUMBER

LEG_NUMBER

SCHEDULED_DEPARTURE_TIM

DEPARTURE_AIRPORT_CODE

ARRIVAL_AIRPORT_CODE SCHEDULED_ARRIVAL_TIME

5111 452
12-APR-00 10.11.13.000000 AM
9999 1000
12-APR-00 12.12.00.000000 PM

FLIGHT_NUMBER LEG_NUMBER

SCHEDULED_DEPARTURE_TIME DEPARTURE_AIRPORT_CODE

ARRIVAL_AIRPORT_CODE

SCHEDULED_ARRIVAL_TIME

852 432
12-APR-00 11.13.13.000000 AM
1000 1111
12-APR-00 12.12.00.000000 PM

10 rows selected.

Increase the fare amount by 5% .

SQL> select * from fare;


FLIGHT_NUMBER FARE_CODE AMOUNT RESTRICTION

1018 75 9500 Non Refundable


1227 40 10500 Refundable
1432 175 8900 Non Refundable
4442 50 10000 Non Refundable
1751 70 55000 Refundable
37160 60 3500 Refundable
63027 35 5500 Refundable
181815 40 8900 Non Refundable
51191 26 45000 Refundable
8502 70 57000 Refundable

10 rows selected.

SQL> update fare set AMOUNT=AMOUNT+AMOUNT*(5/100); 10rows

updated.

SQL> SELECT * FROM FARE;

FLIGHT_NUMBER FARE_CODE AMOUNT RESTRICTION

1018 75 9975 Non Refundable


1227 40 11025 Refundable
1432 175 9345 Non Refundable
4442 50 10500 Non Refundable
1751 70 57750 Refundable
37160 60 3675 Refundable
63027 35 5775 Refundable
181815 40 9345 Non Refundable
51191 26 47250 Refundable
8502 70 59850 Refundable

10 rows selected.

Create a view for Q.3

SQL> create view flight_leg3 as (select flight_number


"flight_number",leg_number
"leg_number",arrival_airport_code "arrival_airport_code" from flight_leg); View

created.

SQL> select * from flight_leg3;


flight_number leg_number arrival_airport_code

108 144 9999


127 133 8888
142 111 7777
442 155 6666
171 177 5555
3710 188 4444
6302 199 3333
18115 542 2222
5111 452 1000
852 432 1111

10 rows selected.

Create a view with airplane id,company name where


max_seats- total_number_of_seats>10.

SQL>create view derivedtable1 as (select a.airplane_id,a1.company from


airplane a, airplane_type a1 where
a.airplane_type=a1.airplane_type_name and a1.max_seats-
a.total_number_of_seats>10);
View created.

SQL> select * from derivedtable1; no

rows selected

Update a company name in the view in Q.7.

SQL>cannot modify a column which maps to a non-key-preserved table

Display the structure of all tables.

SQL> DESC AIRPORT;


Name Null? Type

AIRPORT_CODE NOT NULL NUMBER(10)


NAME VARCHAR2(30)
CITY VARCHAR2(20)
STATE VARCHAR2(20)
COUNTRY VARCHAR2(20)
SQL> DESC FLIGHT;
Name Null? Type

FLIGHT_NUMBER NOT NULL NUMBER(10)


AIRLINE VARCHAR2(40)
WEEKDAYS VARCHAR2(30)

SQL> DESC FLIGHT_LEG;


Name Null? Type

FLIGHT_NUMBER NOT NULL NUMBER


LEG_NUMBER NOT NULL NUMBER
SCHEDULED_DEPARTURE_TIME TIMESTAMP(6)
DEPARTURE_AIRPORT_CODE NUMBER
ARRIVAL_AIRPORT_CODE NUMBER
SCHEDULED_ARRIVAL_TIME TIMESTAMP(6)

SQL> DESC LEG_INSC;


Name Null? Type

FLIGHT_NUMBER NOT NULL NUMBER(9)


LEG_NUMBER NOT NULL NUMBER(5)
DATE1 NOT NULL DATE
NUMBER_OF_AVAILABLE_SEATS NUMBER(4)
AIRPLANE_ID NUMBER(10)
DEPARTURE_AIRPORT_CODE NUMBER(9)
DEPARTURE_TIME TIMESTAMP(6)
ARRIVAL_AIRPORT_CODE NUMBER(9)
ARRIVAL_TIME TIMESTAMP(6)

SQL> DESC FARE;


Name Null? Type

FLIGHT_NUMBER NOT NULL NUMBER(9)


FARE_CODE NOT NULL NUMBER(9)
AMOUNT NUMBER(10,2)
RESTRICTION VARCHAR2(25)
SQL> DESC AIRPLANE_TYPE;
Name Null? Type

AIRPLANE_TYPE_NAME NOT NULL VARCHAR2(15)


MAX_SEATS NUMBER(3)
COMPANY VARCHAR2(25)

SQL> DESC CAN_LAND;


Name Null? Type

AIRPLANE_TYPE_NAME NOT NULL VARCHAR2(15)


AIRPORT_CODE NOT NULL VARCHAR2(10)

SQL> DESC AIRPLANE;


Name Null? Type

AIRPLANE_ID NOT NULL NUMBER(10)


TOTAL_NUMBER_OF_SEATS NUMBER(3)
AIRPLANE_TYPE VARCHAR2(20)

SQL> DESC SEAT_RESERVATION;


Name Null? Type

FLIGHT_NUMBER NOT NULL NUMBER(10)


LEG_NUMBER NOT NULL NUMBER(5)
DATE2 NOT NULL DATE
SEAT_NUMBER NOT NULL NUMBER(3)
CUSTOMER_NAME VARCHAR2(20)
CUSTOMER_PHONE NUMBER(10)
ADDRESS VARCHAR2(50)

Drop the unique constraint added.

SQL> select constraint_name from user_constraints where


table_name='AIRPORT';

CONSTRAINT_NAME

SYS_C006997

SQL> alter table airport drop constraint SYS_C006997; Table


altered.
Create a sequence with minimum value 1 max 200 ,increment by 2
start with 4 to generate values to the airplane id column.

SQL> create sequence sequence1 start with 4 increment by 2 maxvalue200


minvalue 1;
SQL> update airplane set airplane_id=sequence1.nextval;
10 rows updated.

SQL> SELECT * FROM AIRPLANE;

AIRPLANE_ID TOTAL_NUMBER_OF_SEATS AIRPLANE_TYPE

4 250 Boeing 800


6 250 Airbus 320
18 250 Boeing 737
10 250 Boeing 737
8 250 Airbus 330
14 250 Airbus 320
20 250 Airbus 320 neo
22 250 Airbus 220
16 250 Airbus 380
12 250 Airbus 320

10 rows selected.

Alter the above sequence to have maximum

value 300. SQL> alter sequence sequence1 maxvalue 300;

Sequence altered.

Create an index on state column of airport

table. SQL> create index index1 on airport (state); Index

created.

Select the flights on wednesday('wed'). ( Query with Object type)

SQL> select * from flight where weekdays='%wed%'; norows

selected
Write a query to show the constraints(plus column)
created on the Table already existing.

SQL> SELECT CONSTRAINT_NAME FROM USER_CONSTRAINTS WHERE


TABLE_NAME='FLIGHT_LEG';

CONSTRAINT_NAME

SYS_C006999
SYS_C007000
FLIGHT_PRIM
E

Write a query to show the sequences created by the user.

select sequence_name from user_sequences;

Write a query to show the procedures ,functions, triggers already


created.

SQL> SELECT NAME FROM USER_SOURCE WHERE TYPE='PROCEDURE';

SQL>SELECT TEXT FROM USER_SOURCE WHERE NAME='GRT'; SQL>SELECT

TRIGGER_NAME,TRIGGER_TYPE FROM USER_TRIGGERS;


Write a query to show all the details about constraints.
Write a query to see the body of a procedure or function.

SELECT TEXT FROM USER_SOURCE WHERE NAME='GRT';

Write a query to see the body of trigger.


SQL> SELECT TRIGGER_BODY FROM USER_TRIGGERS;

You might also like