SQL DELETE Statement: Removing Student Data from a Table
How to Remove a Student's Data from a Database Table Using SQL
Imagine a student named 'Tom' has left the school. As a database administrator, you need to ensure Tom's details are removed from the student table. The correct SQL statement to achieve this is:
B) delete from student where student_name='Tom'
Explanation:
- delete from student: This part specifies that you want to delete rows from the table named 'student'.
- where student_name='Tom': This condition filters the deletion to only include rows where the 'student_name' column has the value 'Tom'.
Incorrect Options:
- A) delete table student name='Tom': This syntax is incorrect. You cannot use 'delete table' to remove specific rows. It's used to drop the entire table.
- C) delete student where name='Tom': This might work if your table has a column named 'name'. However, it's good practice to use descriptive column names like 'student_name' for clarity.
- D) delete 'Tom': This statement is incomplete and doesn't specify the table or the condition for deletion.
原文地址: https://www.cveoy.top/t/topic/oCyc 著作权归作者所有。请勿转载和采集!