0% found this document useful (0 votes)
63 views3 pages

DBMS Week - 7 (1) (1) 1

The document contains the SQL queries performed on passenger and reservation tables to practice various SQL commands like CREATE TABLE, INSERT, ALTER, DELETE, UPDATE, SELECT etc. It creates tables with primary keys, foreign keys and constraints, inserts data, modifies structure by renaming columns and changing data types, deletes and updates records, and writes various SELECT queries to retrieve data based on conditions on columns.

Uploaded by

beast noir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views3 pages

DBMS Week - 7 (1) (1) 1

The document contains the SQL queries performed on passenger and reservation tables to practice various SQL commands like CREATE TABLE, INSERT, ALTER, DELETE, UPDATE, SELECT etc. It creates tables with primary keys, foreign keys and constraints, inserts data, modifies structure by renaming columns and changing data types, deletes and updates records, and writes various SELECT queries to retrieve data based on conditions on columns.

Uploaded by

beast noir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Roll No:21R21A0573

21R21A0596 Name: HAFSA


ASHIYAALIYA
BEGUM
Experiment No:7 Experiment Name: PRACTICE PROBLEMS
Date Of Experiment:25/11/2022 Batch No:1

AIM: create a table with necessary pk,fk,and constraints(age is greater than 20,pmobile must be
unique)
SQL QUERY:
create table passenger (Pid INT, Pname varchar(30), age INT ,pmobile number(20),pmailid
varchar (40),plocation varchar (30),pbalance number(30),PRIMARY
KEY(Pid),CHECK(age>=20),UNIQUE(pmobile));
INSERT INTO passenger values(101,'lokesh',39,911212131,'[email protected]','banglore',20000)
INSERT INTO passenger values(102,'rajesh',65,9112121312,'[email protected]','delhi',15000)
INSERT INTO passenger values(103,'ramesh',60,9112121313,'[email protected]','hyderabad',30000)
INSERT INTO passenger values(104,'divya',45,9112121315,'[email protected]','mumbai',250000)
INSERT INTO passenger values(105,'meghana',20,91121213156,'[email protected]','New
Delhi',1500000)
INSERT INTO passenger values(160,'ashmitha',26,9391063700,'[email protected])

SQL QUERY:
create table reservation(rid INT, rdate Date, rtype varchar(10),rpid INT,rfrom varchar(12),fto
varchar(15),rprice number(10),PRIMARY KEY(rid),FOREIGN KEY(rpid) references passenger(Pid));
INSERT INTO reservation values(1101,'25nov2022','1ac',101,'banglore','chennai',2000);
INSERT INTO reservation values(1102,'18aug2022','2ac',102,'delhi','hyderabad',3000);
INSERT INTO reservation values(1103,'25aug2022','1ac',103,'hyderabad','chennai',1500);
INSERT INTO reservation values(1104,'30aug2022','2ac',104,'delhi','hyderabad',3000);
INSERT INTO reservation values(1105,'28sep2022','2ac',105,'banglore','hyderabad',5000);

AIM: alter the pname to passenger name


SQL QUERY: ALTER table passenger RENAME column Pname to passenger_name;
AIM: alter the column pbalance should not be not null
SQL QUERY: ALTER table passenger modify pbalance NOT NULL

AIM: alter the data type of pbalance to float


Roll No:21R21A0573
21R21A0596 Name: HAFSA
ASHIYAALIYA
BEGUM
Experiment No:7 Experiment Name: PRACTICE PROBLEMS
Date Of Experiment:25/11/2022 Batch No:1

SQL QUERY: ALTER table passenger modify pbalance float


AIM: insert the data from the given tables
update the passenger details "109, mahesh,9111235659,[email protected],pune)
update the passenger details "110, priya,9111235700,[email protected],pune)
SQL QUERY:
insert into passenger values(109,'mahesh',26,9111235659,'[email protected]','pune',0.00)
insert into passenger values(110,'priya',30,911123565958,'[email protected]','pune',0.00)
AIM: delete the passenger details 105)
SQL QURY: Delete from passenger where Pid=109
AIM: in sql how many passenger are travelling in the month of AUGUST

SQL QUERY: select count(*) from reservation where rdate like '%AUG%';
AIM: list the passengers who are from hyderabad, banglore
SQL QUERY:
select passenger_name from passenger where plocation ='hyderabad' or plocation='banglore'

AIM: list the passengers who are from New delhi or mumbai
SQL QUERY: select passenger_name from passenger where plocation ='New Delhi' or plocation='mumbai'

AIM: SQL statement that selects all passenegrs from the "passenegers" table, sorted ascending by the "plocation" and
descending by the "pname" column
SQL QUERY:
select * from passenger ORDER BY plocation ASC,passenger_name DESC;

AIM: list the no of passengers travelling in NOVEMBER


SQL QUERY: select count(*) from reservation where rdate like '%NOV%';
Roll No:21R21A0573
21R21A0596 Name: HAFSA
ASHIYAALIYA
BEGUM
Experiment No:7 Experiment Name: PRACTICE PROBLEMS
Date Of Experiment:25/11/2022 Batch No:1

AIM: find min and maximum of ticket reservation table


SQL QUERY: select min(rprice),max(rprice) from reservation

AIM: find the average, minimum and maximum price of tickets in reservation table and rename the columns accordingly
SQL QUERY: select min(rprice) as minimum,max(rprice) as maximum,avg(rprice) as average from reservation

AIM: find how many passengers are the in the passeneger table
SQL QUERY: select count(Pid) from passenger
AIM: SQL statement lists the number of passenger in each plocation, sorted high to low
SQL QUERY: select count(plocation),plocation from passenger GROUP BY plocation ORDER BY
count(plocation) DESC

AIM: in SQL create a view that selects every passenger in the "passenegr" table with a price higher
than the average price
SQL QUERY: CREATE VIEW name_pass as select passenger_name from passenger

AIM: in sql find the passenger details who are senior citizens
SQL QUERY: select * from passenger where age>=60

You might also like