Test Index

Structured Query Language (SQL) Get it on Google PlayDownload on the App Store CBSE Board Videos

© examsnet.com
Question : 42 of 58
Marks: +1, -0
Consider the table Rent_cab, given below :
Table : Rent_cab
VcodeVNameMakeColorCharges
101Big carCarusWhite15
102Small carPolestarSilver10
103Family carWindspeedBlack20
104ClassicStudioWhite30
105LuxuryTronaRed9
Based on the given table, write SQL queries for the following :
(i) Add a primary key to a column name Vcode.
(ii) Increase the charges of all the cabs by 10%.
(iii) Delete all the cabs whose maker name is "Carus".
[CBSE 2024 Compartment]
Solution:  
(i)
ALTER TABLE Rent_cab
ADD PRIMARY KEY (Vcode);
ALTER TABLE ... ADD PRIMARY KEY adds the primary key constraint to the existing column Vcode (its values 101 to 105 are unique and not NULL).
(ii)
UPDATE Rent_cab
SET Charges = Charges * 1.1;
Increasing by 10% means new charge = old charge + 10% of it = old charge × 1.1 (for example 15 becomes 16.5). With no WHERE clause, every row is updated.
(iii)
DELETE FROM Rent_cab
WHERE Make = 'Carus';
Only the rows whose maker is Carus (Vcode 101) are deleted.
© examsnet.com
Advertisements
Go to Question: