TRUNCATE करना
TRUNCATE एक table से सारी rows जल्दी remove करता है, DELETE से कहीं ज़्यादा तेज़।
In this page:
Syntax
TRUNCATE TABLE table_name;
TRUNCATE TABLE table_name RESTART IDENTITY;
TRUNCATE
TRUNCATE table एक या ज़्यादा tables को row by row delete करने की बजाय इनकी data files discard करके खाली करता है। RESTART IDENTITY identity या serial counters reset करता है, और CASCADE इसे reference करने वाली tables भी truncate करता है।
PostgreSQL में TRUNCATE transactional है लेकिन एक strong lock लेता है, और कोई row-level delete triggers fire नहीं करता।
Note:
- TRUNCATE ...
- RESTART IDENTITY auto-numbering reset करता है।
उदाहरण: TRUNCATE
shop=# SELECT COUNT(*) FROM log_entries;
count
---------
2500000
shop=# TRUNCATE TABLE log_entries RESTART IDENTITY;
TRUNCATE TABLE
shop=# SELECT COUNT(*) FROM log_entries;
count
-------
0
shop=# BEGIN;
shop=*# TRUNCATE orders CASCADE;
NOTICE: truncate cascades to table "order_items"
shop=*# ROLLBACK;
⚠️ Run this in your own terminal or Node.js environment.
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. #}
आम गलतियां
- जहाँ आपको एक WHERE clause चाहिए वहाँ TRUNCATE इस्तेमाल करना
- foreign keys exist करने पर CASCADE भूल जाना
- यह realize न करना कि यह एक exclusive lock लेता है
चैप्टर सारांश
- TRUNCATE सारी rows जल्दी remove करता है
- RESTART IDENTITY counters reset करता है
- CASCADE foreign keys follow करता है
- यह एक ACCESS EXCLUSIVE lock लेता है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: