1.
In a database there are two tables 'Customer' and 'Bill' as shown below:
(i) How many rows and how many columns will be there in the Cartesian product of these two
tables?
(ii) Which column in the 'Bill' table is the foreign key?
i) There will be 5 columns and 15 rows in the Cartesian product of these two tables.
ii) CustID in the bill table is a foreign key
2. Consider the tables HANDSETS and CUSTOMER given below:
With reference to these tables, Write commands in SQL for (i) and (ii) and output for (iii) below:
(i) Display the CustNo, CustAddress and corresponding SetName for each customer.
(ii) Display the Customer Details for each customer who uses a Nokia handset.
(iii) select SetNo, SetName from Handsets, customer where SetNo = SetCode and CustAddress =
'Delhi';
i) Select custno, custaddress, setname
from handsets, customer
where setcode=setno;
ii) Select customer.*
from handsets, customer
where setcode=setno and setname like “Nokia%”;
iii) SetNo SetName
N2 Nokia 3G
B1 BlackBerry
3. In a database there are two tables "Company" and "Model" as shown below:
(i) Identify the foreign key column in the table Model.
(ii) Check every value in CompiD column of both the tables. Do you fnd any discrepancy?
i) ComID is the foreign key in model table
ii) The discrepancy is a value 4 in the compID feld of Model table.
4. Consider the tables DOCTORS and PATIENTS given below:
W1th reference to these tables, wnte commands m SQL for (1) and (II) and output for (iii) below:
(i) Display the PatNo, PatName and corresponding DocName for each patient
(ii) Display the list of all patients whose OPD_Days are MWF.
(iii) select OPD_Days, Count(*) from Doctors, Patients where Patients.Department =
Doctors.Department Group by OPD_Days;
i) Select PatNo, patName, DocName
From Doctors, Patients
Where Doctors.DocID=Patients.DocID;
ii) Select Patients.*
From Doctors, Patients
Where Doctors.docID=Patients.DocID amd OPD_Days=”MWF”;
iii) OPD_Days Count(*)
TTS 2
MWF 3
5. In a database there are two tables "Product" and "Client" as shown below :
Write the commands in SQL queries for the following :
(i) To display the details of Product whose Price is in the range of 40 and 120 (Both values included)
(ii) To display the ClientName, City from table Client and ProductName and Price from table
Product, with their corresponding matching P ID.
(iii) To increase the Price of all the Products by 20.
i) Select *
From Product
where price between 40 and 120;
ii) Select clientName,city,productName,price
From Product,Client
Where Product.P_ID=Client.P_ID;
iii) Update Product
Set price=price+20;
6. In a. Database School there are two tables Member and Division as show below.
(i) Identify the foreign key in the table Member.
(ii) What output, you will get, when an equi-join query is executed to get the NAME from Member
Table and corresponding DivName from Division table ?
i) DivNo is a foreign key in member table
ii) Name Divname
Shankhya Media
Sunish Dance
7. Consider the tables ‘Flights’ & ‘Fares’ given below:
Flights
FNO SOURCE DEST NO_OF_FL NO_OF_STO
P
IC301 MUMBAI BANGALORE 3 2
IC799 BANGALORE KOLKATA 8 3
MC101 DELHI VARANASI 6 0
IC302 MUMBAI KOCHI 1 4
AM812 LUCKNOW DELHI 4 0
MU499 DELHI CHENNAI 3 3
Fares
FNO AIRLINES FARE TAX
IC301 Indian Airlines 9425 5
IC799 Spice Jet 8846 10
MC101 Deccan Airlines 4210 7
IC302 Jet Airways 13894 5
AM812 Indian Airlines 4500 6
MU499 Sahara 12000 4
With reference to these tables, write commands in SQL for (i) and (ii) and output for (iii)
below:
i. To display fight number, source, airlines of those fights where fare is less than Rs.
10000.
ii. To count total no of Indian Airlines fights starting from various cities.
iii. SELECT FLIGHTS.FNO, NO_OF_FL, AIRLINES FROM FLIGHTS,FARES WHERE FLIGHTS.FNO =
FARES.FNO AND SOURCE=’DELHI’;
i) Select Flights.FNO, Source,airlines
From Flights, Fares
Where Flights.FNO=Fares.FNO and fare<10000;
ii) Select Sum(No_of_Fl)
From Flights, Fares
Where Flights.FNO=Fares.FNO and airlines=”Indian Airlines”;
iii) FLIGHTS.FNO NO_OF_FL AIRLINES
MC101 6 Deccan Airlines
MU499 3 Sahara
8. A table STUDENT has 5 rows and 3 columns. Table ACTIVITY has 4 rows and 2 columns.
What will be the cardinality and degree of the Cartesian product of them ?
The degree will be 5
The cardinality will be 20
9. Consider the following table named “GARMENT”.
What is the degree and cardinality of ‘Garment’ table ?
Degree=5
Cardinality=6
10. In a Database, there are two tables given below :
Write SQL Queries for the following :
(i) To display employee ids, names of employees, job ids with corresponding job titles.
(ii) To display names of employees, sales and corresponding job titles who have achieved sales
more than 1300000.
(iii) To display names and corresponding job titles of those employee who have ‘SINGH’ (anywhere)
in their names.
(iv) Identify foreign key in the table EMPLOYEE.
i) Select EmployeeID, Name, JobID, JobTitle
From Employee, Job
Where Employee.jobid=job.jobid;
ii) Select Name, Sales, Jobtitle
From Employee, Job
Where Employee.jobid=job.jobid and sales>1300000;
iii) Select Name, Jobtitle
From Employee, Job
Where Employee.jobid=job.jobid and name like “%Singh%”;
iv) JobID
11. Consider the tables given below.
Salesperson Orders
i. The SalespersonId column in the "Salesperson" table is the Primary Key.The
SalespersonId column in the "Orders" table is a Foreign KEY.
ii. Can the ‘SalespersonId’ be set as the primary key in table ‘Orders’. Give reason.
Ii. No salespersonID cannot be set as the primary key in orders table as two
salesperson can give multiple orders, so the ordered will be primary key and
salespersonID will be the foreign key which will refer its values from the
salespersonid feld of salesperson table.
12. With reference to the above given tables, Write commands in SQL for (i) and
(ii) and output for (iii) below:
i. To display SalespersonID, names, orderids and order amount of all salespersons.
ii. To display names ,salespersons ids and order ids of those sales persons whose names
start with ‘A’ and sales amount is between 15000 and 20000.
iii. SELECT Salesperson.SalespersonId, name, age, amount FROM Salesperson, orders
WHERE Salesperson.salespersonId= Orders.salespersonId AND AGE BETWEEN 30 AND
45;
i. Select Salesperson.salespersonID, Name, OrderID
From Salespersons, orders
Where Salesperson.salespersonID=Orders.SalespersonID;
ii. Select Salesperson.salespersonID, Name, OrderID
From Salespersons, orders
Where Salesperson.salespersonID=Orders.SalespersonID
and name like “A%” and amount between 15000 and 20000;
iii. Salesperson.SalespersonId name age amount
2 Sunil 34 54000
5 Chris 34 24000
13. Consider the tables given below :
Table : Faculty
TeacherId Name Address State PhoneNumber
T101 Savita Sharma A-151, Adarsh Delhi 991019564
Nagar
T102 Deepak Ghai K-5/52, Vikas Mumbai 893466448
Vihar
T103 MahaLakshmi D-6 Delhi 981166568
T104 Simi Arora Mumbai 658777564
Table : Course
CourseId Subject TeacherId Fee
C101 Introductory Mathematics T101 4500
C103 Physics T101 5000
C104 Introductory Computer Science T102 4000
C105 Advance Computer Science T104 6500
(i) Which column is used to relate the two tables ?
(ii) Is it possible to have a primary key and a foreign key both in one table ? Justify your answer
with the help of table given above.
i) TeacherID
ii) Yes, it is possible to have both Primary and foreign key in one table. For Example in the
above course table CourseID is a primary key and teacherid is the foreign key.
14. With reference to the above given tables, write commands in SQL for (i) and (ii)
and output for (iii) :
(i) To display CourseId, TeacherId, Name of Teacher, Phone Number of Teachers living in Delhi.
(ii) To display TeacherID, Names of Teachers, Subjects of all teachers with names of Teachers
starting with ‘S’.
(iii) SELECT CourseId, Subject,Course.TeacherId,Name,PhoneNumber FROM
Faculty,Course WHERE Faculty.TeacherId = Course.TeacherId AND Fee>=5000;
i) Select coursed, Course.TeacherID, Name, PhoneNumber
From Faculty, Course
Where Faculty.TeacherID=Course.TeacherID and state=”Delhi”;
ii) Select Faculty.TeacherID, Name, Subject
From Faculty, Course
Where Faculty.TeacherID=Course.TeacherID and name like “S%”;
iii) CourseId Subject Course.TeacherId Name
PhoneNumber
C105 Advance Computer Science T104 Simi Arora
658777564
15. Consider the tables given below which are linked with each other and maintains referential
integrity:
Table: SAP
Table : Store
With reference to the above given tables, write commands in SQL for (i) and (ii) and output for (iii)
below:
i. To display the ItemCode,ItemName and ReceivedDate of all the items .
ii. To display SAPID,ItemName,ItemStorageLocation of all the items whose Received date is
after 2nd May 2016.
iii. SELECT SAPID,ItemName,STOREID FROM SAP,Store WHERE
SAP.ItemCode=Store.ItemCode AND StoreLocation = “Hauz Khas”
iv. What will be the degree and cardinality of the cartesian product formed while combining
both the above given tables ‘SAP’ and ‘Store’ ?
v. Sangeeta is not able to add a new record in the table ‘Store’ through the following query:
Insert into store values (1206,1006,’Karol Bagh’, ‘2016/07/25’);
Identify the error if there is any
i. Select SAP.ItemCode, ItemName, ReceivedDate
From SAP, Store
Where SAP.ItemCode=Store.ItemCode;
ii. Select SapID, ItemName, storeLocation
From SAP, Store
Where SAP.ItemCode=Store.ItemCode and ReceivedDate>”2016-05-02”;
iii. SAPID ItemName STOREID
S1001 Receiver 1201
S1004 Inverter 1204
iv. The degree will be 8
The cardinality will be 25
v. She will not be able to insert the record as 1006 ItemCode is not there in the
itemCode feld in SAP table and since ItemCode in store table is a foreign key
so it will refer its value from the itemcode feld of SAP table.
35