﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Kalpesh Thaker / Article Discussions / Article Discussions by Author  / Tips for Optimizing Data Manipulation Language / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 19 Jun 2013 06:50:01 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Tips for Optimizing Data Manipulation Language</title><link>http://www.sqlservercentral.com/Forums/Topic173891-207-1.aspx</link><description>&lt;P&gt;&lt;FONT size=+0&gt;TRUNCATE TABLE is logged but in a different way than a normal DELETE.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=+0&gt;From BOL: "The DELETE statement removes rows one at a time and records an entry in the transaction log for each deleted row. TRUNCATE TABLE removes the data by deallocating the data pages used to store the table's data, and &lt;STRONG&gt;only the page deallocations are recorded in the transaction log&lt;/STRONG&gt;."&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=+0&gt;It is perfectly possible to rollback a truncate table.  &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;FONT size=+0&gt;create table test (f varchar(10))&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;FONT size=+0&gt;insert into test values ('truncate')insert into test values ('table')&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;FONT size=+0&gt;BEGIN TRANTRUNCATE TABLE testSELECT * FROM testROLLBACK TRAN&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;FONT size=+0&gt;SELECT * FROM test&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;FONT size=+0&gt;drop table test&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=+0&gt;I also don't understand the 'invalidates transaction log' statement.  Could you elaborate this please?&lt;/FONT&gt;&lt;/P&gt;</description><pubDate>Wed, 04 May 2005 01:06:00 GMT</pubDate><dc:creator>WesleyB</dc:creator></item><item><title>RE: Tips for Optimizing Data Manipulation Language</title><link>http://www.sqlservercentral.com/Forums/Topic173891-207-1.aspx</link><description>&lt;P&gt;Hey,&lt;/P&gt;&lt;P&gt;Thanks for the info, &lt;/P&gt;&lt;P&gt;I thing Xavier comments are not 100% accurate. I just wanted to clarify.&lt;/P&gt;&lt;P&gt;This is from SQL Help. Truncate table is not logged see below&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Joe&lt;/P&gt;&lt;P&gt;TRUNCATE TABLE is functionally identical to DELETE statement with no WHERE clause: both remove all rows in the table. But TRUNCATE TABLE is faster and uses fewer system and transaction log resources than DELETE. &lt;/P&gt;&lt;P&gt;The DELETE statement removes rows one at a time and records an entry in the transaction log for each deleted row. TRUNCATE TABLE removes the data by deallocating the data pages used to store the table's data, and only the page deallocations are recorded in the transaction log.&lt;/P&gt;&lt;P&gt;TRUNCATE TABLE removes all rows from a table, but the table structure and its columns, constraints, indexes and so on remain. The counter used by an identity for new rows is reset to the seed for the column. If you want to retain the identity counter, use DELETE instead. If you want to remove table definition and its data, use the DROP TABLE statement.&lt;/P&gt;&lt;P&gt;You cannot use TRUNCATE TABLE on a table referenced by a FOREIGN KEY constraint; instead, use DELETE statement without a WHERE clause. Because TRUNCATE TABLE is not logged, it cannot activate a trigger. &lt;/P&gt;&lt;P&gt;TRUNCATE TABLE may not be used on tables participating in an indexed view.&lt;/P&gt;</description><pubDate>Tue, 03 May 2005 14:21:00 GMT</pubDate><dc:creator>JOSEPH HOGG-230209</dc:creator></item><item><title>RE: Tips for Optimizing Data Manipulation Language</title><link>http://www.sqlservercentral.com/Forums/Topic173891-207-1.aspx</link><description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;Thanks for this worthy article.&lt;/P&gt;&lt;P&gt;I have a question about it: the author states that TRUNCATE TABLE "invalidates the transaction log".  I'm certainly missing the point here; indeed, TRUNCATE TABLE is a fully logged operation that can, for instance, be rollbacked.&lt;/P&gt;&lt;P&gt;The three troubles underlined, in the BOL, with TRUNCATE TABLE are:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;It resets IDENTITY columns to the seed.&lt;/LI&gt;&lt;LI&gt;It cannot be used on a table referenced by a FOREIGN KEY.&lt;/LI&gt;&lt;LI&gt;It cannot activate a trigger.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Kalpesh, maybe you meant one of these three?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Xavier&lt;/P&gt;</description><pubDate>Thu, 28 Apr 2005 23:31:00 GMT</pubDate><dc:creator>xblondel</dc:creator></item><item><title>RE: Tips for Optimizing Data Manipulation Language</title><link>http://www.sqlservercentral.com/Forums/Topic173891-207-1.aspx</link><description>Great article but I would add a caution on using query hints as they can become invalid as data changes.</description><pubDate>Thu, 28 Apr 2005 08:48:00 GMT</pubDate><dc:creator>Gary E. Vernon</dc:creator></item><item><title>RE: Tips for Optimizing Data Manipulation Language</title><link>http://www.sqlservercentral.com/Forums/Topic173891-207-1.aspx</link><description>that article is bookmark worthy.  thanks Kalpesh.</description><pubDate>Thu, 28 Apr 2005 07:34:00 GMT</pubDate><dc:creator>Greg Johnson-186398</dc:creator></item><item><title>Tips for Optimizing Data Manipulation Language</title><link>http://www.sqlservercentral.com/Forums/Topic173891-207-1.aspx</link><description>Comments posted to this topic are about the content posted at &lt;A HREF="http://www.sqlservercentral.com/columnists/kThaker/tipsforoptimizingdatamanipulationlanguage.asp"&gt;http://www.sqlservercentral.com/columnists/kThaker/tipsforoptimizingdatamanipulationlanguage.asp&lt;/A&gt;</description><pubDate>Mon, 11 Apr 2005 20:24:00 GMT</pubDate><dc:creator>Kalpesh-198559</dc:creator></item></channel></rss>