{"id":3930,"date":"2025-06-06T20:40:24","date_gmt":"2025-06-06T20:40:24","guid":{"rendered":"https:\/\/w3buddy.com\/?post_type=cposts&#038;p=3930"},"modified":"2025-06-07T09:57:26","modified_gmt":"2025-06-07T09:57:26","slug":"sql-delete","status":"publish","type":"cposts","link":"https:\/\/w3buddy.com\/blog\/notes\/sql\/sql-delete\/","title":{"rendered":"SQL DELETE"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>DELETE<\/code> statement is used to <strong>remove one or more rows<\/strong> from a table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd39 Basic Syntax<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>DELETE FROM table_name\nWHERE condition;<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u26a0\ufe0f Always use a <code>WHERE<\/code> clause to avoid deleting everything!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd39 Examples<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Delete a specific employee\nDELETE FROM employees\nWHERE employee_id = 101;\n\n-- Delete all employees from the IT department\nDELETE FROM employees\nWHERE department = 'IT';<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd39 Delete All Rows (Be Cautious!)<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Delete all rows (but keep the table)\nDELETE FROM employees;\n\n-- Oracle tip: Use TRUNCATE for faster delete (no WHERE allowed)\nTRUNCATE TABLE employees;<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd39 With Subqueries<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Delete employees who are not assigned to any department\nDELETE FROM employees\nWHERE department_id NOT IN (\n  SELECT id FROM departments\n);<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde0 Quick Recap<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Action<\/th><th>Syntax Example<\/th><\/tr><\/thead><tbody><tr><td>Delete with condition<\/td><td><code>DELETE FROM table WHERE ...<\/code><\/td><\/tr><tr><td>Delete all rows<\/td><td><code>DELETE FROM table;<\/code><\/td><\/tr><tr><td>Fast delete (Oracle)<\/td><td><code>TRUNCATE TABLE table_name;<\/code><\/td><\/tr><tr><td>Delete using subquery<\/td><td><code>DELETE WHERE col IN (SELECT ...)<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 Use <code>DELETE<\/code> to clean up data\u2014carefully!<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The DELETE statement is used to remove one or more rows from a table. \ud83d\udd39 Basic Syntax \u26a0\ufe0f Always use a WHERE clause to avoid deleting everything! \ud83d\udd39 Examples \ud83d\udd39 Delete All Rows (Be Cautious!) \ud83d\udd39 With Subqueries \ud83e\udde0 Quick Recap Action Syntax Example Delete with condition DELETE FROM table WHERE &#8230; Delete all rows [&hellip;]<\/p>\n","protected":false},"template":"","meta":{"googlesitekit_rrm_CAowu461DA:productID":""},"categories":[952,979],"class_list":["post-3930","cposts","type-cposts","status-publish","hentry","category-notes","category-sql"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts\/3930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/cposts"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=3930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=3930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}