Test Index
Structured Query Language (SQL)
© examsnet.com
Question : 42 of 58
Marks:
+1,
-0
Consider the table Rent_cab, given below :Table : Rent_cab
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".
| Vcode | VName | Make | Color | Charges |
|---|---|---|---|---|
| 101 | Big car | Carus | White | 15 |
| 102 | Small car | Polestar | Silver | 10 |
| 103 | Family car | Windspeed | Black | 20 |
| 104 | Classic | Studio | White | 30 |
| 105 | Luxury | Trona | Red | 9 |
[CBSE 2024 Compartment]
Solution:
(i)
ALTER TABLE Rent_cabADD 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_cabSET 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_cabWHERE Make = 'Carus';Only the rows whose maker is Carus (Vcode 101) are deleted.
© examsnet.com
Go to Question: