CS TERM 1 PRACTICAL FILE (2) - Merged
CS TERM 1 PRACTICAL FILE (2) - Merged
(TERM 1)
ANIKET AGARWAL
CLASS-XII-C
ROLL NO-5
(b) Show all information where capacity > noofstudents in order of rtno:
(c) Show area_covered where Distance > 20 and Charges < 80000:
(d) Show transporter-wise total number of students traveling:
(e) Show Rtno, Area_covered, and average cost per student (Charges /
Noofstudents):
(f) Add a new record with data (11, "Moti Bagh", 35, 32, 10, "Kisan Tours", 35000):
ANS:-
INSERT INTO SchoolBus (Rtno, Area_covered, Capacity, Noofstudents, Distance,
Transporter, Charges) VALUES (11, 'Moti Bagh', 35, 32, 10, 'Kisan Tours', 35000);
(b) Display NAME, STIPEND, SUBJECT, and annual stipend (12 × STIPEND)
c) Count the number of students who are either PHYSICS or COMPUTER Sc.
Graduates
(c) List all patient names with their date of admission in ascending order
(d) Display patient’s name, charges, and age for male patients only
(e) Count the number of patients with age > 20
(k) Display details of all patients whose names start with ‘Z’
(c) Display the coach’s name and Acodes in ascending order of Acode
(d) Display the content of the Activity table whose ScheduleDate is earlier than
01/01/2004 in ascending order of ParticipantsNum
(e) Display the names of coaches who are not associated with any activity at all
Output of Queries
● The ROUND(number, -1) function rounds the number to the nearest 10s
place (negative precision).
● Output: 340
b) List business done by the movies showing only MovieID, MovieName and
Total_Earning.
e) List MovieID, MovieName and Cost for all movies with ProductionCost greater than
10,000 and less than 1,00,000.
f) List details of all movies which fall in the category of comedy or action.
g) List details of all movies which have not been released yet
Assumed Table Creation Schema
Table: UNIFORM
Table: COST
Rectifying the Anomalies
Before inserting into the COST table, the handkerchief's details must first be inserted
into the UNIFORM table to avoid a foreign key violation.
The FOREIGN KEY constraint ensures that any data entered into the COST table will
require a corresponding record in the UNIFORM table.
If not already present, add the following constraint to the COST table:
This enforces referential integrity, preventing invalid UCode values in the COST table.
To ensure a UCode can only be assigned if the UName is provided, add a NOT NULL
constraint to the UName column in the UNIFORM table:
This ensures that UName must be specified whenever a new UCode is added.
To enforce the condition that the price of an item is greater than zero in the COST table,
add a CHECK constraint:
Final Schema
Table: UNIFORM
Table: COST
a) Create the table Product with appropriate data types and constraints
c) List the Product Code, Product Name, and price in descending order of
their Product Name. If PName is the same, display in ascending order of
price.
ANIKET AGARWAL
CLASS XII-C
ROLL NO-5
SQL
Create Table:
(b) To show all information of students where capacity is more than the number of
students in order of Rtn.
(c) To show Area_covered for buses covering more than 20 km, but charges less
than 80000.
(e) To show Rtn, Area_covered, and average cost per student for all routes
where average cost per student is Charges / No_of_students.
(f) Add a new record with the following data:
(iii) Select the average Charges from SchoolBus where Transporter = 'Anand
Travels':
(a) List the names of those students who have obtained DIV 1 sorted by NAME.
(b) Display a report, listing NAME, STIPEND, SUBJECT, and amount of stipend
received in a year (assuming STIPEND is paid every month).
(c) To count the number of students who are either PHYSICS or COMPUTER Sc.
graduates.
(e) Give the output of the following SQL statements based on the GRADUATE table:
Table: GUIDE
(a) Display the names of all the activities with their Acodes in descending order.
(b) Display the sum of PrizeMoney for the activities played in each of the
stadiums separately.
(c) Display the coach’s name and Acodes in ascending order of Acode from the
table COACH.
(d) Display the content of the Activity table whose ScheduleDate is earlier than
01/01/2004 in ascending order of ParticipantsNum.
(e) Display the names of coaches who are not associated with any activity at all.
(f) Display the names of activities and their corresponding coach names.
(iv) SELECT Name, ActivityName FROM activity A, COACH C WHERE A.Acode = C.Acode
AND A.ParticipantsNum = 10;
Example Interaction:
Content of NAdd.TXT after replacement: