{"id":88,"date":"2026-03-06T06:43:37","date_gmt":"2026-03-06T06:43:37","guid":{"rendered":"https:\/\/gigz.pk\/sql\/?post_type=lesson&#038;p=88"},"modified":"2026-03-16T18:51:53","modified_gmt":"2026-03-16T18:51:53","slug":"truncate","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/sql\/lesson\/truncate\/","title":{"rendered":"\u00a0TRUNCATE"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>TRUNCATE<\/strong> is a Data Definition Language (DDL) command used in SQL to <strong>quickly remove all rows from a table<\/strong>. Unlike <code>DELETE<\/code>, it does not log individual row deletions, making it faster for large tables.<\/p>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1773572811147\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Key Points<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Purpose<\/strong>\n<ul class=\"wp-block-list\">\n<li>Removes all data from a table.<\/li>\n\n\n\n<li>Resets any auto-increment counters (depends on database system).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Syntax<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">TRUNCATE TABLE table_name;<\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Differences Between TRUNCATE and DELETE<\/strong><\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Feature<\/th><th>TRUNCATE<\/th><th>DELETE<\/th><\/tr><\/thead><tbody><tr><td>Logs<\/td><td>Minimal<\/td><td>Full row-level logging<\/td><\/tr><tr><td>WHERE clause<\/td><td>Not allowed<\/td><td>Allowed<\/td><\/tr><tr><td>Speed<\/td><td>Faster<\/td><td>Slower for large tables<\/td><\/tr><tr><td>Trigger activation<\/td><td>Usually does not fire triggers<\/td><td>Triggers fire<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>Use Cases<\/strong>\n<ul class=\"wp-block-list\">\n<li>Clearing a table before loading new data.<\/li>\n\n\n\n<li>Quickly removing all records without affecting table structure.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Precautions<\/strong>\n<ul class=\"wp-block-list\">\n<li>Cannot be rolled back in some databases (like MySQL with non-transactional tables).<\/li>\n\n\n\n<li>Removes <strong>all rows<\/strong>, so be sure you don\u2019t need the data.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Example<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">TRUNCATE TABLE employees;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This command removes all records from the <code>employees<\/code> table but keeps the table structure intact.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/sql\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">Intermediate SQL for Data Professionals (SQL-201) > Data Manipulation > TRUNCATE<\/span><\/span><\/div>\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"menu_order":36,"template":"","class_list":["post-88","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>\u00a0TRUNCATE - SQL Learning Hub<\/title>\n<meta name=\"description\" content=\"&quot;Learn SQL TRUNCATE TABLE: fast way to remove all rows, reset counters, and optimize large table deletion safely.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/sql\/lesson\/truncate\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u00a0TRUNCATE - SQL Learning Hub\" \/>\n<meta property=\"og:description\" content=\"&quot;Learn SQL TRUNCATE TABLE: fast way to remove all rows, reset counters, and optimize large table deletion safely.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/sql\/lesson\/truncate\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Learning Hub\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-16T18:51:53+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/truncate\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/truncate\\\/\",\"name\":\"\u00a0TRUNCATE - SQL Learning Hub\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/#website\"},\"datePublished\":\"2026-03-06T06:43:37+00:00\",\"dateModified\":\"2026-03-16T18:51:53+00:00\",\"description\":\"\\\"Learn SQL TRUNCATE TABLE: fast way to remove all rows, reset counters, and optimize large table deletion safely.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/truncate\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/truncate\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/truncate\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Intermediate SQL for Data Professionals (SQL-201) > Data Manipulation > TRUNCATE\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/\",\"name\":\"SQL Learning Hub\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u00a0TRUNCATE - SQL Learning Hub","description":"\"Learn SQL TRUNCATE TABLE: fast way to remove all rows, reset counters, and optimize large table deletion safely.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/sql\/lesson\/truncate\/","og_locale":"en_US","og_type":"article","og_title":"\u00a0TRUNCATE - SQL Learning Hub","og_description":"\"Learn SQL TRUNCATE TABLE: fast way to remove all rows, reset counters, and optimize large table deletion safely.","og_url":"https:\/\/gigz.pk\/sql\/lesson\/truncate\/","og_site_name":"SQL Learning Hub","article_modified_time":"2026-03-16T18:51:53+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/sql\/lesson\/truncate\/","url":"https:\/\/gigz.pk\/sql\/lesson\/truncate\/","name":"\u00a0TRUNCATE - SQL Learning Hub","isPartOf":{"@id":"https:\/\/gigz.pk\/sql\/#website"},"datePublished":"2026-03-06T06:43:37+00:00","dateModified":"2026-03-16T18:51:53+00:00","description":"\"Learn SQL TRUNCATE TABLE: fast way to remove all rows, reset counters, and optimize large table deletion safely.","breadcrumb":{"@id":"https:\/\/gigz.pk\/sql\/lesson\/truncate\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/sql\/lesson\/truncate\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/sql\/lesson\/truncate\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/sql\/"},{"@type":"ListItem","position":2,"name":"Intermediate SQL for Data Professionals (SQL-201) > Data Manipulation > TRUNCATE"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/sql\/#website","url":"https:\/\/gigz.pk\/sql\/","name":"SQL Learning Hub","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/sql\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/sql\/wp-json\/wp\/v2\/lesson\/88","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/sql\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/sql\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/sql\/wp-json\/wp\/v2\/media?parent=88"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}