Test Index

CBSE Class 12 Computer Science 2025 Paper Compartment Get it on Google PlayDownload on the App Store

© examsnet.com
Question : 34 of 37
Marks: +1, -0
Assume that you are working for ABC Corporation (ABCC). ABCC allots contracts to different contractors for some of its works. The data of Contracts and Contractors are kept in the tables Work and Contractor respectively. Following are a few records from these two tables of ABCC’s database.
Table : Work
W_IDC_IDW_NameW_Amt
P0001C_01Painting20000
E0001C_01Electrical50000
D0001C_02Dumping10000
Table : Contractor
C_IDC_NamePhoneemail
C_01M. Khan & Sons1232311MK@xyz.com
C_02Acharya Pvt. Ltd.2323311APL@xyz.com
C_03Charu Corp.NULLCCP@pqr.xyz
Note : The tables contain many more records than shown here.
As an employee of ABCC, you are required to write the SQL queries for the following :
(I) To display all the records from the Work table in alphabetical order of W_Name.
(II) To display the names of contractors where W_Amt is more than 15000.
(III) To display the structure of Work table.
(IV) (a) To count total number of records present in Work table.
OR
(b) To delete the records of contractors whose phone number is not known.
Solution:  
(I)
SELECT * FROM Work
ORDER BY W_Name;
(II) C_Name is in Contractor and W_Amt is in Work, so join the two tables on the common column C_ID:
SELECT C_Name
FROM Work, Contractor
WHERE Work.C_ID = Contractor.C_ID
AND W_Amt > 15000;
(Add DISTINCT after SELECT to show each contractor only once.)
(III)
DESCRIBE Work;
(or DESC Work;)
(IV) (a)
SELECT COUNT(*) FROM Work;
OR (b) An unknown phone number is stored as NULL, and NULL is tested with IS NULL (not = NULL):
DELETE FROM Contractor
WHERE Phone IS NULL;
© examsnet.com
Advertisements
Go to Question: