Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

Consider the table Personal given below:

Table: Personal

Question 29 CBSE Sample Question Paper 2024 Boards - Teachoo.PNG

Based on the given table, write SQL queries for the following:

(i) Increase the salary by 5% of personals whose allowance is known.

Answer

Answer by student:

UPDATE Personal 

SET Salary = Salary * 1.05 

WHERE Allowance IS NOT NULL;

Detailed answer by teachoo:

  • The question asks us to write a SQL query to increase the salary by 5% of personals whose allowance is known. To do this, we use the UPDATE statement, which modifies the data in a table. The syntax of the UPDATE statement is: 

UPDATE table_name 

SET column_name = expression 

WHERE condition;

    • The table_name is the name of the table that we want to update. In this case, it is Personal.
    • The column_name is the name of the column that we want to update. In this case, it is Salary.
    • The expression is the new value that we want to assign to the column. In this case, it is Salary * 1.05, which means multiplying the current salary by 1.05 to get a 5% increase.
    • The condition is an optional clause that specifies which rows to update. If we omit the condition, all rows in the table will be updated. In this case, we want to update only those rows where Allowance is not NULL, which means that the allowance is known. We use the IS NOT NULL operator to check for non-null values.
    • The semicolon (;) is used to end the SQL statement.

So, the SQL query to increase the salary by 5% of personals whose allowance is known is: 

UPDATE Personal 

SET Salary = Salary * 1.05 

WHERE Allowance IS NOT NULL;

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.