Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Tips for Optimizing Data Manipulation Language Expand / Collapse
Author
Message
Posted Monday, April 11, 2005 8:24 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, July 28, 2005 7:56 AM
Points: 27, Visits: 1
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/kThaker/tipsforoptimizingdatamanipulationlanguage.asp
Post #173891
Posted Thursday, April 28, 2005 7:34 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, August 15, 2005 12:58 PM
Points: 159, Visits: 1
that article is bookmark worthy. thanks Kalpesh.
Post #178253
Posted Thursday, April 28, 2005 8:48 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, November 26, 2008 12:03 PM
Points: 38, Visits: 21
Great article but I would add a caution on using query hints as they can become invalid as data changes.
Post #178308
Posted Thursday, April 28, 2005 11:31 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, April 09, 2010 9:22 AM
Points: 270, Visits: 16

Hi!

Thanks for this worthy article.

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.

The three troubles underlined, in the BOL, with TRUNCATE TABLE are:

  • It resets IDENTITY columns to the seed.
  • It cannot be used on a table referenced by a FOREIGN KEY.
  • It cannot activate a trigger.

Kalpesh, maybe you meant one of these three?

Thanks!

Xavier




Post #178568
Posted Tuesday, May 03, 2005 2:21 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, January 25, 2006 8:05 AM
Points: 1, Visits: 1

Hey,

Thanks for the info,

I thing Xavier comments are not 100% accurate. I just wanted to clarify.

This is from SQL Help. Truncate table is not logged see below

Thanks

Joe

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.

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.

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.

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.

TRUNCATE TABLE may not be used on tables participating in an indexed view.

Post #179613
Posted Wednesday, May 04, 2005 1:06 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Monday, May 02, 2011 5:35 AM
Points: 493, Visits: 45

TRUNCATE TABLE is logged but in a different way than a normal DELETE.

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 only the page deallocations are recorded in the transaction log."

It is perfectly possible to rollback a truncate table. 

create table test
(f varchar(10))

insert into test values ('truncate')
insert into test values ('table')


BEGIN TRAN
TRUNCATE TABLE test
SELECT * FROM test
ROLLBACK TRAN

SELECT * FROM test

drop table test

I also don't understand the 'invalidates transaction log' statement.  Could you elaborate this please?

Post #179682
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse