{"id":8760,"date":"2022-05-16T06:03:00","date_gmt":"2022-05-16T04:03:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=8760"},"modified":"2022-07-13T12:21:23","modified_gmt":"2022-07-13T10:21:23","slug":"empty-sql-server-table-truncate","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/","title":{"rendered":"Empty a SQL Server table (TRUNCATE)"},"content":{"rendered":"\n<p>How do I clear all the data in a SQL Server table with a query? From SSMS, connect to the SQL Server database and use the TRUNCATE TABLE command to clear the data from the table.<\/p>\n\n\n\n<p>Note that the TRUNCATE command is different from the DELETE query in that all data is removed without any filter. The TRUNCATE command is therefore faster and recommended.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-empty-a-sql-server-table-with-the-truncate-table-query\">Empty a SQL Server table with the Truncate Table query<\/h2>\n\n\n\n<p>This command deletes all the data stored in the table. Be careful, this command is irreversible. Remember to check your database backups to avoid losing data.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">Note that this action is irreversible.<\/mark><\/strong><\/p>\n\n\n\n<p>Simply use a T-SQL query from <strong><a href=\"https:\/\/expert-only.com\/en\/ssms\/download-sql-server-management-studio-18-ssms\/\">SQL Server Management Studio<\/a><\/strong>, with the TRUNCATE TABLE command.<\/p>\n\n\n\n<p>Note that the <a href=\"https:\/\/www.geeksforgeeks.org\/difference-between-delete-and-truncate\/\" target=\"_blank\" rel=\"noreferrer noopener\">TRUNCATE query is different from the DELETE<\/a> command, especially in terms of performance. A DELETE FROM command scans all rows before deleting and allows you to filter the rows to be deleted.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">TRUNCATE TABLE [dbo][SALES];\nGO\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Minimum rights needed on the table to execute a TRUNCATE<\/h3>\n\n\n\n<p>The TRUNCATE command has more impact than a simple DELETE, especially because the truncate cannot be undone via the <strong><a href=\"https:\/\/expert-only.com\/en\/sql-server-db\/empty-the-sql-server-transaction-log-and-fix-error-9002\/\">transaction log<\/a><\/strong>. The minimum right to execute a TRUNCATE command is ALTER. Because the DBMS considers this to be a modification of the table.<\/p>\n\n\n\n<p>To delete the table completely, the data structure and the data must be deleted. To avoid generating error messages, then <strong><a href=\"https:\/\/expert-only.com\/en\/t-sql\/check-if-table-exists-in-sql-server\/\">test the existence of the SQL Server table before deleting it<\/a><\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-tutoriels-et-exemples-sql-server-et-microsoft-it wp-block-embed-tutoriels-et-exemples-sql-server-et-microsoft-it\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"Fj0ItFKdl0\"><a href=\"https:\/\/expert-only.com\/en\/t-sql\/check-if-table-exists-in-sql-server\/\">Check if table exists in SQL Server<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Check if table exists in SQL Server&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/t-sql\/check-if-table-exists-in-sql-server\/embed\/#?secret=LuVN2mmTJV#?secret=Fj0ItFKdl0\" data-secret=\"Fj0ItFKdl0\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>How do I clear all the data in a SQL Server table with a query? From SSMS, connect to the SQL Server database and use the TRUNCATE TABLE command to clear the data from the table. Note that the <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/\" title=\"Empty a SQL Server table (TRUNCATE)\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":6041,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[454],"tags":[],"class_list":{"0":"post-8760","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-t-sql"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.7 (Yoast SEO v26.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Empty a SQL Server table (TRUNCATE) - T-SQL<\/title>\n<meta name=\"description\" content=\"How to delete all data in a SQL Server table ? Use the SQL Truncate statement to quickly delete all rows from a table quickly.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Empty a SQL Server table (TRUNCATE)\" \/>\n<meta property=\"og:description\" content=\"How to delete all data in a SQL Server table ? Use the SQL Truncate statement to quickly delete all rows from a table quickly.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL and IT Tutorials\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-16T04:03:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-13T10:21:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/one-hundred-64289A5CC0F_1920x1080.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Expert-Only\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@expert_only\" \/>\n<meta name=\"twitter:site\" content=\"@expert_only\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Expert-Only\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/\"},\"author\":{\"name\":\"Expert-Only\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\"},\"headline\":\"Empty a SQL Server table (TRUNCATE)\",\"datePublished\":\"2022-05-16T04:03:00+00:00\",\"dateModified\":\"2022-07-13T10:21:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/\"},\"wordCount\":252,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/one-hundred-64289A5CC0F_1920x1080.jpeg\",\"articleSection\":[\"T-SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/\",\"url\":\"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/\",\"name\":\"Empty a SQL Server table (TRUNCATE) - T-SQL\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/one-hundred-64289A5CC0F_1920x1080.jpeg\",\"datePublished\":\"2022-05-16T04:03:00+00:00\",\"dateModified\":\"2022-07-13T10:21:23+00:00\",\"description\":\"How to delete all data in a SQL Server table ? Use the SQL Truncate statement to quickly delete all rows from a table quickly.\",\"breadcrumb\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/#primaryimage\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/one-hundred-64289A5CC0F_1920x1080.jpeg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/one-hundred-64289A5CC0F_1920x1080.jpeg\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"en\",\"item\":\"https:\/\/expert-only.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Empty a SQL Server table (TRUNCATE)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/expert-only.com\/en\/#website\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"name\":\"SQL and IT Tutorials\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/expert-only.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/expert-only.com\/en\/#organization\",\"name\":\"Expert-Only\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"width\":381,\"height\":174,\"caption\":\"Expert-Only\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\",\"https:\/\/x.com\/expert_only\",\"https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\",\"name\":\"Expert-Only\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"caption\":\"Expert-Only\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Empty a SQL Server table (TRUNCATE) - T-SQL","description":"How to delete all data in a SQL Server table ? Use the SQL Truncate statement to quickly delete all rows from a table quickly.","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:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/","og_locale":"en_US","og_type":"article","og_title":"Empty a SQL Server table (TRUNCATE)","og_description":"How to delete all data in a SQL Server table ? Use the SQL Truncate statement to quickly delete all rows from a table quickly.","og_url":"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/","og_site_name":"SQL and IT Tutorials","article_publisher":"https:\/\/www.facebook.com\/ExpertOnlyCom\/","article_published_time":"2022-05-16T04:03:00+00:00","article_modified_time":"2022-07-13T10:21:23+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/one-hundred-64289A5CC0F_1920x1080.jpeg","type":"image\/jpeg"}],"author":"Expert-Only","twitter_card":"summary_large_image","twitter_creator":"@expert_only","twitter_site":"@expert_only","twitter_misc":{"Written by":"Expert-Only","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/#article","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/"},"author":{"name":"Expert-Only","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef"},"headline":"Empty a SQL Server table (TRUNCATE)","datePublished":"2022-05-16T04:03:00+00:00","dateModified":"2022-07-13T10:21:23+00:00","mainEntityOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/"},"wordCount":252,"commentCount":0,"publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/one-hundred-64289A5CC0F_1920x1080.jpeg","articleSection":["T-SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/","url":"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/","name":"Empty a SQL Server table (TRUNCATE) - T-SQL","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/#primaryimage"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/one-hundred-64289A5CC0F_1920x1080.jpeg","datePublished":"2022-05-16T04:03:00+00:00","dateModified":"2022-07-13T10:21:23+00:00","description":"How to delete all data in a SQL Server table ? Use the SQL Truncate statement to quickly delete all rows from a table quickly.","breadcrumb":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/#primaryimage","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/one-hundred-64289A5CC0F_1920x1080.jpeg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/one-hundred-64289A5CC0F_1920x1080.jpeg","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"en","item":"https:\/\/expert-only.com\/en\/"},{"@type":"ListItem","position":2,"name":"Empty a SQL Server table (TRUNCATE)"}]},{"@type":"WebSite","@id":"https:\/\/expert-only.com\/en\/#website","url":"https:\/\/expert-only.com\/en\/","name":"SQL and IT Tutorials","description":"","publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/expert-only.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/expert-only.com\/en\/#organization","name":"Expert-Only","url":"https:\/\/expert-only.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","width":381,"height":174,"caption":"Expert-Only"},"image":{"@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ExpertOnlyCom\/","https:\/\/x.com\/expert_only","https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA"]},{"@type":"Person","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef","name":"Expert-Only","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","caption":"Expert-Only"}}]}},"_links":{"self":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/8760","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/comments?post=8760"}],"version-history":[{"count":0,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/8760\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/6041"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=8760"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=8760"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=8760"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}