← Back to PostgreSQL Course | Chapter 4: Inserting & Modifying Data | Lesson 4 of 7

DELETE करना

DELETE एक condition match करने वाली rows remove करता है।

In this page:

  1. DELETE
Syntax
sql
DELETE FROM table_name
WHERE condition;

DELETE

DELETE FROM table WHERE condition matching rows remove करता है, जबकि बिना WHERE के DELETE FROM table हर row remove करता है लेकिन table structure रखता है। Deleted rows dead mark होती हैं और बाद में VACUUM से clean up होती हैं। Foreign keys deletes restrict या cascade कर सकती हैं।

Note: delete करने से पहले WHERE condition को SELECT से try करें।

उदाहरण: DELETE

sql
CREATE TABLE sessions (id INTEGER PRIMARY KEY, user_name TEXT, expired INTEGER);
INSERT INTO sessions VALUES (1, 'ada', 1), (2, 'bob', 0), (3, 'cy', 1), (4, 'di', 0);
SELECT COUNT(*) AS before_delete FROM sessions;
DELETE FROM sessions WHERE expired = 1;
SELECT user_name FROM sessions ORDER BY id;

-- Output:
-- before_delete
-- 4
-- user_name
-- bob
-- di
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. WHERE clause भूल जाना
  2. foreign keys से reference की गई rows delete करना
  3. यह उम्मीद करना कि disk space तुरंत free हो जाएगी
चैप्टर सारांश
  • DELETE FROM rows remove करता है
  • WHERE rows चुनता है
  • बिना WHERE यह table खाली कर देता है
  • VACUUM बाद में space reclaim करता है
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.