sql
  1. sql-delete-row

SQL DELETE ROW

The SQL DELETE ROW command is used to remove a specific row or rows from a table.

Syntax:

DELETE FROM table_name
WHERE condition;

Example:

Suppose we have a table named students with the following data:

id name age gender
1 John Doe 20 M
2 Jane Doe 22 F
3 Bob Smith 19 M
4 Mary Jane 21 F

Now we want to delete the row with id = 3 from the students table.

The SQL statement would be:

DELETE FROM students
WHERE id = 3;

Output:

After executing the SQL statement, the students table will look like this:

id name age gender
1 John Doe 20 M
2 Jane Doe 22 F
4 Mary Jane 21 F

Explanation:

  • DELETE FROM is the command used to remove rows from a table.
  • students is the name of the table we want to delete rows from.
  • WHERE is used to specify which row(s) to delete based on a condition.
  • id = 3 is the condition used to specify which row to delete.

Use:

The SQL DELETE ROW command is used when we want to remove one or more rows from a table based on certain conditions.

Important Points:

  • Be careful when using the SQL DELETE ROW command as it permanently removes data from the table.
  • Always use a WHERE clause when using the DELETE command to prevent accidentally deleting all rows from a table.

Summary:

The SQL DELETE ROW command is used to remove one or more rows from a table based on a condition. It is important to use a WHERE clause to prevent accidentally deleting all rows from a table.

Published on: