Which of the following commands is correct to delete the values in the…
2023
Which of the following commands is correct to delete the values in the relation teaches?
- A.
Delete from teaches;
- B.
Delete from teaches where Id = Null;
- C.
Remove table teaches;
- D.
More than one of the above
- E.
None of the above
Attempted by 1104 students.
Show answer & explanation
Correct answer: A
To delete values from a relation (table) in SQL, the correct command is DELETE FROM followed by the table name. Let's analyze each option: Option A: 'Delete from teaches;' — This command deletes all rows from the 'teaches' table. It is syntactically correct and fulfills the requirement to delete values. Option B: 'Delete from teaches where Id = Null;' — This is incorrect because 'Null' should be 'NULL' in SQL. Also, NULL values must be checked using 'IS NULL', not '='. The correct syntax would be 'WHERE Id IS NULL'. Option C: 'Remove table teaches;' — This is invalid because 'Remove' is not a valid SQL command for deleting data. The correct command to delete data is 'DELETE', not 'REMOVE'. Option D: 'More than one of the above' — This is incorrect because only Option A is valid. Options B and C are invalid, so more than one is not correct. Option E: 'None of the above' — This is incorrect because Option A is a valid command to delete values from the 'teaches' table. Therefore, the correct command is Option A.