Question
Which SQL command is used to remove only specific rows
from a table while preserving the structure and other rows?Solution
The DELETE command in SQL is used to remove specific rows from a table based on a WHERE clause condition. Unlike DROP or TRUNCATE, which impact the entire table, DELETE operates on a more granular level, enabling selective removal of data while preserving the table structure and any other rows. For example: DELETE FROM employees WHERE department = 'Sales'; This query removes only the rows from the employees table where the department is 'Sales', leaving all other rows intact. Additionally, the DELETE command logs each deleted row, making it possible to rollback transactions if the database supports it (e.g., in databases using transaction control). This makes DELETE particularly useful for scenarios where precision and rollback capabilities are required. Explanation of Incorrect Options: A) DROP : The DROP command is used to completely remove a table or database, including its structure. It is not selective and deletes the entire object. B) TRUNCATE : While TRUNCATE removes all rows from a table, it does not allow selective deletion. Furthermore, TRUNCATE is faster but does not log individual row deletions, making rollback impossible in most cases. D) REMOVE : This is not a valid SQL command. E) UPDATE : The UPDATE command is used to modify existing data, not to delete it.
Average run scored by a batsman in first ‘x’ matches is 20. In next 5 matches he scored runs with an average of 60 so that his overall average incre...
In a company, the average number of employees named Amit and Chinky is 25. The number of Chinky's name employees is 50% higher than the number of Amit's...
Of the four numbers, whose average is 75, the first is one-fourth of the sum of the last three. The first number is
- A class of 20 students has an average age of 19 years. 5 new students join and the average becomes 17.5 years. Find the average age of the new students.
The average value of the property of Ravi, Sanjay, and Deepak is Rs. 75 lacs. The value of the property of Ravi is Rs. 20 lacs less than the value of th...
- The average of two numbers is 5 more than the smaller number among them. If the greater number is 60% more than the smaller number, then find the sum of th...
There are only 220 students living in hostel. If 20 students left hostel, then overall expenditure of mess is reduced by Rs. 800 weekly but per student ...
The average weight of 7 boxes P, Q, R, S, T, U and V is 72kg. Another box A is added to group and the average now becomes 70kg. If another box C whose ...
- In a company team, if 3 employees each weighing 65 kg resign, the average weight of the remaining team members drops by 1 kg. But if 4 employees with an av...
The average cost of 3 chairs is Rs. 10000. The average cost decrease by 22% when one more chair is included. What is the cost price of the 4th