Delete Row - SQL
To delete a specific row from a table in SQL, you use the DELETE FROM statement. Here's the basic syntax:
Syntax
DELETE FROM table_name
WHERE condition;
- table_name: The name of the table from which you want to delete rows.
- WHERE: Optional clause that specifies the condition for deleting rows. If omitted, all rows in the table will be deleted.
- condition: The condition that must be met for the rows to be deleted.
Let's say you have a table named articles and you want to delete a row where the article_id is 1001:
article_id | Student Name | Address |
---|---|---|
1001 | Kulpati Maurya | Delhi |
1002 | Rakesh Kumar | Kolkata |
1003 | T. Raghubindra | Kerala |
Syntax
DELETE FROM articles
WHERE article_id = 1001;
This SQL statement will delete the row(s) from the articles table where the article_id is equal to 1001.
If you want to delete all rows from the table, you can omit the WHERE clause:
Syntax
DELETE FROM articles;
This will delete all rows from the articles table.
Remember to use the DELETE statement carefully, especially when using it without a WHERE clause, as it will remove all rows from the table, leading to permanent data loss. Always double-check your conditions to ensure that only the intended rows are deleted.