Delete Row in SQL
The DELETE query in SQL is used to remove or delete record or row from a table. It allows you to delete multiple rows using Where condition that match specific conditions. you can use multiple condition to delete row. you can delete multiple rows at a time .It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be intact.
some important points about Delete statement:
- The DELETE statement is used to remove specific rows from a table based on specified conditions.
- It is a data manipulation statement that selectively deletes rows that match the given criteria.
- DELETE retains the table structure, indexes, and other associated objects, and only removes the specified rows.
- Cascading deletions in a database automatically delete related records in child tables when a record in the parent table is deleted. It helps maintain data consistency and referential integrity. However, caution should be exercised when using cascading deletions to avoid unintended data loss.
About Delete statement
In DELETE statement DELETE is a keyword used to indicate that you want to remove data from a table.
FROM specifies the table from which you want to delete rows.
WHERE is an optional clause that allows you to specify conditions for deleting rows.
The conditions in the WHERE clause determine which rows will be deleted. For example, you can delete rows where a certain column has a specific value.
Here's the basic syntax of the DELETE statement:
Example
DELETE FROM table_name
WHERE condition;
Example
DELETE FROM employees
WHERE employee_id = 1001;
Delete multiple rows
Example
DELETE FROM customers
WHERE country = 'USA' AND status = 'Inactive';
Delete rows with Joins
Example
DELETE t1
FROM table1 t1
JOIN table2 t2 ON t1.column_name = t2.column_name
WHERE condition;
Delete All Rows
Example
DELETE FROM table_name;
Difference Between Delete, Drop and Truncate Statement
DELETE:
- What it Does:
- Control:
- Rollback:
- Table Structure:
- Performance:
DROP:
- What it Does:
- Control:
- Rollback:
- Table Structure:
- Performance:
TRUNCATE:
- What it Does:
- Control:
- Rollback:
- Table Structure:
- Performance:
0 Comments
Post a Comment