DBMS Lab Record_Sandeep

Click here to load reader

  • date post

    26-Mar-2015
  • Category

    Documents

  • view

    389
  • download

    6

Embed Size (px)

Transcript of DBMS Lab Record_Sandeep

E - R DIAGRAMSBUS : Bus no, Source, Destination, Class

Busno BUS

Source

Destinatio n

Class

PASSENGER

: Pnr_No, Ticket_No, Name, Age, Sex, Ppno

Pnr_No

Ticket_No

Name

PASSENGER

Age

Sex

Ppno

RESERVATION

: Pnr_No, Journey_Date, No_Of_Seats, Address, Contact_No, Status

Pnr_No

Journey_Dat e

No_Of_Seat s

RESERVATION

Address

Contact_N o

Status

CANCELLATION

: Pnr_No, Journey_Date, No_Of_Seats, Address, Contact_No, Status

Pnr_No

Journey_Dat e

No_Of_Seat s

CANCELLATION

Address

Contact_N o

Status

TICKET

: Ticket_No, Journey_Date, Age, Sex, Source, Destination, Dep_Time

Ticket_No

Journey_Dat e

Age

TICKET Sex Dep_Time

Source

Destination

CREATION OF BUS TABLESQL> CREATE TABLE BUS (BUSNO NUMBER(5) PRIMARY KEY,SOURCE VARCHAR2(15),DESTINATION VARCHAR2(15),CLASS VARCHAR(8)); Table created. SQL> DESC BUS Name -------------------------BUSNO SOURCE DESTINATION CLASS Null? -------------NOT NULL Type ------------------NUMBER(5) VARCHAR2(15) VARCHAR2(15) VARCHAR2(8)

SQL> INSERT INTO BUS VALUES(7202,'Secunderabad','Guntur', 'NON-AC'); 1 row created. SQL> INSERT INTO BUS VALUES(2704,'Secunderabad','Howrah', 'AC'); 1 row created. SQL> INSERT INTO BUS VALUES(2714,'Secunderabad','Vijayawada', 'AC'); 1 row created. SQL> INSERT INTO BUS VALUES(2728,'Hyderabad','Visakhapatnam', 'NON-AC'); 1 row created. SQL> INSERT INTO BUS VALUES(2738,'Secunderabad','Kakinada', 'AC'); 1 row created. SQL> INSERT INTO BUS VALUES(2702,'Hyderabad','Mumbai', 'NON-AC'); 1 row created. SQL> SELECT * FROM BUS; BUSNO SOURCE ---------- -------------------7202 Secunderabad 2704 Secunderabad 2714 Secunderabad 2728 Hyderabad 2738 Secunderabad 2702 Hyderabad 6 rows selected. SQL> commit; Commit complete. DESTINATION -------------------Guntur Howrah Vijayawada Visakhapatnam Kakinada Mumbai CLASS ----------NON_AC AC AC NON_AC AC NON_AC

CREATION OF PASSENGER TABLESQL> CREATE TABLE PASSENGER(PNR_NO NUMBER(10)PRIMARY KEY,TICKET_NO NUMBER(10),NAME VARCHAR2(15),AGE NUMBER(3),SEX CHAR(6),PPNO VARCHAR(15)); Table created. SQL> DESC PASSENGER Name Null? ------------------------------- -------------PNR_NO NOT NULL TICKET_NO NAME AGE SEX PPNO Type -----------------NUMBER(10) NUMBER(10) VARCHAR2(15) NUMBER(3) CHAR(6) VARCHAR2(15)

SQL> INSERT INTO PASSENGER VALUES(1234,4321,'Bharath',23,'Male','A1234'); 1 row created. SQL> INSERT INTO PASSENGER VALUES(2345,5432,'Sandeep',21,'Male','B2345'); 1 row created. SQL> INSERT INTO PASSENGER VALUES(3456,6543,'Bhagya',21,'Female','C3456'); 1 row created. SQL> INSERT INTO PASSENGER VALUES(4567,7654,'Akash',40,'Male','D4567'); 1 row created. SQL> INSERT INTO PASSENGER VALUES(5678,8765,'Shireesha',31,'Female','E5678'); 1 row created. SQL> INSERT INTO PASSENGER VALUES(6789,9876,'Anil',35,'Male','F6789'); 1 row created. SQL> INSERT INTO PASSENGER VALUES(7890,0987,'Shiva',25,'Male','G7890'); 1 row created. SQL> SELECT * FROM PASSENGER; PNR_NO TICKET_NO ------------- -----------------1234 4321 2345 5432 3456 6543 4567 7654 5678 8765 6789 9876 7890 987 7 rows selected. SQL> commit; Commit complete. NAME AGE --------------- ---------Bharath 23 Sandeep 21 Bhagya 21 Akash 40 Shireesha 31 Anil 35 Shiva 25 SEX -------Male Male Female Male Female Male Male PPNO ---------A1234 B2345 C3456 D4567 E5678 F6789 G7890

CREATION OF RESERVATION TABLESQL> CREATE TABLE RESERVATION(PNR_NO NUMBER(10)REFERENCES PASSENGER(PNR_NO),JOURNEY_DATE DATE,NO_OF_SEATS NUMBER(5),ADDRESS VARCHAR2(50),CONTACT_NO NUMBER(11),STATUS CHAR(5)); Table created. SQL> DESC RESERVATION Name Null? ---------------------------- --------PNR_NO JOURNEY_DATE NO_OF_SEATS ADDRESS CONTACT_NO STATUS Type -----------NUMBER(10) DATE NUMBER(5) VARCHAR2(50) NUMBER(11) CHAR(5)

SQL> INSERT INTO RESERVATION VALUES(1234,'15-Dec-2010',4,'Hyderabad',8801255245,'Yes'); 1 row created. SQL> INSERT INTO RESERVATION VALUES(2345,'01-Jan-2011',2,'Hyderabad',8099341624,'No'); 1 row created. SQL> INSERT INTO RESERVATION VALUES(3456,'06-Jun-2011',6,'Secunderabad',8143879126,'Yes'); 1 row created. SQL> INSERT INTO RESERVATION VALUES(4567,'20-Dec-2010',1,'Chennai',9966335543,'Yes'); 1 row created. SQL> INSERT INTO RESERVATION VALUES(5678,'14-Jan-2011',3,'Karimnagar',9908109596,'Yes'); 1 row created. SQL> INSERT INTO RESERVATION VALUES(6789,'31-Dec-2010',2,'Warangal',9885554321,'No'); 1 row created. SQL> INSERT INTO RESERVATION VALUES(7890,'11-Dec-2010',5,'Ongole',9908109595,'No'); 1 row created. SQL> SELECT * FROM RESERVATION; PNR_NO JOURNEY_D ------------- ------------------1234 15-DEC-10 2345 01-JAN-11 3456 05-JUN-11 4567 20-DEC-10 5678 14-JAN-11 6789 31-DEC-10 7890 11-DEC-10 7 rows selected. SQL> COMMIT; Commit complete. NO_OF_SEATS ADDRESS ----------------------- --------------4 Hyderabad 2 Hyderabad 6 Secunderabad 1 Chennai 3 Karimnagar 2 Warangal 5 Ongole CONTACT_NO ---------------------8801255245 8099341624 8143879126 9966335543 9908109596 9885554321 9908109595 STATUS -----------Yes No Yes Yes Yes No No

CREATION OF CANCELLATION TABLESQL> CREATE TABLE CANCELLATION(PNR_NO NUMBER(10)REFERENCES PASSENGER(PNR_NO),JOURNEY_DATE DATE,NO_OF_SEATS NUMBER(5),ADDRESS VARCHAR2(50),CONTACT_NO NUMBER(11),STATUS CHAR(5)); Table created. SQL> DESC CANCELLATION Name Null? Type ------------------------- --------- -----------------PNR_NO NUMBER(10) JOURNEY_DATE DATE NO_OF_SEATS NUMBER(5) ADDRESS VARCHAR2(50) CONTACT_NO NUMBER(11) STATUS CHAR(5) SQL> INSERT INTO CANCELLATION VALUES(6789,'31-Dec-2010',2,'Warangal',9885554321,'No'); 1 row created. SQL> INSERT INTO CANCELLATION VALUES(7890,'11-Dec-2010',5,'Ongole',9908109595,'No'); 1 row created. SQL> SELECT * FROM CANCELLATION; PNR_NO ------------6789 7890 JOURNEY_D ------------------31-DEC-10 11-DEC-10 NO_OF_SEATS ADDRESS ----------------------- --------------2 Warangal 5 Ongole CONTACT_NO ---------------------9885554321 9908109595 STATUS -----------No No

SQL> COMMIT; Commit complete.

CREATION OF TICKET TABLESQL> CREATE TABLE TICKET(TICKET_NO NUMBER(10)PRIMARY KEY,JOURNEY_DATE DATE,AGE NUMBER(3),SEX CHAR(6),SOURCE VARCHAR2(15),DESTINATION VARCHAR2(15),DEP_TIME VARCHAR(10)); Table created. SQL> DESC TICKET Name --------------------------TICKET_NO JOURNEY_DATE AGE SEX SOURCE DESTINATION DEP_TIME Null? ----------------NOT NULL Type ------------------NUMBER(10) DATE NUMBER(3) CHAR(6) VARCHAR2(15) VARCHAR2(15) VARCHAR2(10)

SQL> INSERT INTO TICKET VALUES(4321,'15-Dec-2010',23,'Male','Secunderabad','Vijayawada','10:00 AM'); 1 row created. SQL> INSERT INTO TICKET VALUES(5432, 01-JAN-11',21,'Male','Secunderabad','Kakinada','08:00 PM'); 1 row created. SQL> INSERT INTO TICKET VALUES(6543,'05-Jun-2011',21,'Female','Hyderabad','Visakhapatnam','09:00 PM'); 1 row created. SQL> INSERT INTO TICKET VALUES(7654,'20-Dec-2010',40,'Male','Hyderabad','Mumbai','03:00 PM'); 1 row created. SQL> INSERT INTO TICKET VALUES(8765,'14-Jan-2011',21,'Female','Secunderabad','Guntur','07:00 AM'); 1 row created. SQL> INSERT INTO TICKET VALUES(9876,'31-Dec-2010',35,'Male','Secunderabad','Howrah','03:00 PM'); 1 row created. SQL> INSERT INTO TICKET VALUES(0987,'11-DEC-10',25,'Male','Secunderabad',' Vijayawada ','10:00 AM'); 1 row created. SQL> SELECT * FROM TICKET; TICKET_NO -----------------4321 5432 6543 7654 8765 9876 987 7 rows selected. SQL> COMMIT; JOURNEY_D AGE SEX -------------------- -------- ------15-DEC-10 23 Male 01-JAN-11 21 Male 05-JUN-11 21 Female 20-DEC-10 40 Male 14-JAN-11 21 Female 31-DEC-10 35 Male 11-DEC-10 25 Male SOURCE -------------------Secunderabad Secunderabad Hyderabad Hyderabad Secunderabad Secunderabad Secunderabad DESTINATION ----------------------Vijayawada Kakinada Visakhapatnam Mumbai Guntur Howrah Vijayawada DEP_TIME ----------------10:00 AM 08:00 PM 09:00 PM 03:00 PM 07:00 AM 03:00 PM 10:00 AM

Commit complete.

1 QUERIES2

3 1. Display unique PNR_no of all passengers. 4 SQL> SELECT UNIQUE PNR_NO FROM PASSENGER; 5 6 PNR_NO -----------7 1234 8 2345 9 3456 10 4567 11 5678 12 6789 13 7890 14 7 rows selected. 15 2. Display all the names of male passengers. 16 17 SQL> SELECT NAME FROM PASSENGER WHERE SEX='Male'; 18 19 NAME 20 -----------21 Bharath 22 Sandeep 23 Akash 24 Anil 25 Shiva 26 27 3. Display the ticket numbers and names of all the passengers. 28 SQL> SELECT TICKET_NO,NAME FROM PASSENGER; 29 30 TICKET_NO NAME 31 --------------------------32 4321 Bharath 33 5432 Sandeep 34 6543 Bhagya 35 7654 Akash 36 8765 Shireesha 37 9876 Anil 0 987 Shiva 38 7 rows selected. 39 40 4. Display the source and destination having journey time more than 10 hours. 41 42 5. Find the ticket numbers of the passengers whose name start with A and ends with H. 43 SQL> SELECT NAME,TICKET_NO FROM PASSENGER WHERE NAME LIKE 'A%h'; 44 45 NAME TICKET_NO 46 -------------------------47 Akash 7654

0

48 6. Find the names of passengers whose age is between 30 and 45. 49 SQL> SELECT NAME,AGE FROM PASSENGER WHERE AGE BETWEEN 30 AND 45; 50 51 NAME AGE 52 ---------- ----------53 Akash 40 54 Shireesha 31 55 Anil 35 56 57 7. Display all the passengers names beginning with A 58 SQL> SELECT NAME FROM PASSENGER WHERE NAME LIKE 'A%'; 59 60 NAME -----------61 Akash 62 Anil 63 8. Display the sorted list of passengers names 64 SQL> SELECT NAME FROM PASSENGER ORDER BY NAME; 65 66 NAME 67 ------------68 Akash 69 Anil 70 Bhagya 71 Bharath 72 Sandeep 73 Shireesha 74 Shiva 75 7 rows selected. 76 77 9. Display the Bus numbers that travel on Sunday and Wednesday 78 SQL> SELECT BUSNO FROM BUS B,TICKET T WHERE B.SOURCE=T.SOURCE AND B.DESTINATION=T.DESTINATION AND