473,386 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Log Invalidated after truncate table

Hi group,
In one of the books 'Gurus Guide to Transact SQL' i found this info:

------------------------------------------------------------
TRUNCATE TABLE empties a table without logging row deletions in the
transaction log. It can't be used with
tables referenced by FOREIGN KEY constraints, and it invalidates the
transaction log for the entire database.
Once the transaction log has been invalidated, it can't be backed up
until the next full database backup.
------------------------------------------------------------

Does it mean that the log backup taken after table truncation is an
invalid backup?

Help me! i'm lost....

Thanks in advance
Ronin

*** Sent via Developersdex http://www.developersdex.com ***
Nov 23 '05 #1
5 3081
On Thu, 17 Nov 2005 20:03:10 GMT, ronin 47th wrote:
Hi group,
In one of the books 'Gurus Guide to Transact SQL' i found this info:

------------------------------------------------------------
TRUNCATE TABLE empties a table without logging row deletions in the
transaction log. It can't be used with
tables referenced by FOREIGN KEY constraints, and it invalidates the
transaction log for the entire database.
Once the transaction log has been invalidated, it can't be backed up
until the next full database backup.
------------------------------------------------------------

Does it mean that the log backup taken after table truncation is an
invalid backup?

Help me! i'm lost....

Thanks in advance
Ronin


Hi Ronin,

It's not invalid - but it's not useful anymore either.

If you use the full recovery model, a restore to a point in time
consists of two steps:
1. Restore a full backup to restore the database to the state it had
when that full backup was taken;
2. Restore one or more log backups to re-apply all changes that have
been made to the database after the full backup was taken, up to the
point in time where you want the restore to stop.

A TRUNCATE TABLE operation is minimally logged. That means that there is
just enough information in the log file to rollback if the transaction
fails or commit if it doesn't - but not enough to re-apply the changes.

Now, if one change can't be re-applied, you'll agree that it makes no
sense to go on re-applying changes that were done after that change. In
fact, it is very dangerous, since it might ruin your databases data
integrity.

As a result, when you execute TRUNCATE TABLE or other minimally-logged
operations, the effect will be that you can't restore to a point-in-time
between the moment the TRUNCATE TABLE was executed and the next full
backup.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Nov 23 '05 #2
Hugo Kornelis (hugo@pe_NO_rFact.in_SPAM_fo) writes:
A TRUNCATE TABLE operation is minimally logged. That means that there is
just enough information in the log file to rollback if the transaction
fails or commit if it doesn't - but not enough to re-apply the changes.


Reference?

TRUNCATE TABLE logs the extent deallocations, and that is perfecly
enough to reapply the changes.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Nov 23 '05 #3
On Sun, 20 Nov 2005 19:54:45 +0000 (UTC), Erland Sommarskog wrote:
Hugo Kornelis (hugo@pe_NO_rFact.in_SPAM_fo) writes:
A TRUNCATE TABLE operation is minimally logged. That means that there is
just enough information in the log file to rollback if the transaction
fails or commit if it doesn't - but not enough to re-apply the changes.


Reference?

TRUNCATE TABLE logs the extent deallocations, and that is perfecly
enough to reapply the changes.


Hi Erland,

mmmm.... 'kay, I guess you're right.

But then, what DOES the quote that Ronin posted mean?

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Nov 23 '05 #4
Hugo Kornelis (hugo@pe_NO_rFact.in_SPAM_fo) writes:
Hi Erland,

mmmm.... 'kay, I guess you're right.

But then, what DOES the quote that Ronin posted mean?


Just because it is in a guru's guide, does not mean that it is right.
Ken Henderson usually knows his stuff, so it is a little surprising.
Then again, Ronin did not mention issue year or anything. This is an
area where things have changed over time. The statement might have been
true in 4.x. (I recall that it was documented that way. But when you
think of it, it does not make sense. TRUNCATE TABLE is just like DROP
TABLE, except that you keep the metadata.)

I looked up an old discussion in our internal MVP forum, and found
that at the time I had myself conducted a small experiment:

* Set "truncate log on checkpoint" to false.
* DUMP DATABASE
* TRUNCATE TABLE tbl1
* UPDATE tbl2 SET ... WHERE ...
* DUMP TRANSACTION
* LOAD DATABASE
* LOAD TRANSACTION

And this worked well. On SQL 6.5 I should add.

In the same thread I found a statement from an SQL Server dev who said
there is really only one command to break a backup/log chain and that is
ALTER DATABASE SET RECOVERY SIMPLE. (OK, so in SQL 2000 there is also
BACKUP TRANSACTION WITH TRUNCATE_ONLY/NO_LOG. But in SQL 2005, these
commands have no effect.) No DML or DDL on a single table can break
the log chain.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Nov 23 '05 #5
On Sun, 20 Nov 2005 21:10:17 +0000 (UTC), Erland Sommarskog wrote:
Hugo Kornelis (hugo@pe_NO_rFact.in_SPAM_fo) writes:
Hi Erland,

mmmm.... 'kay, I guess you're right.

But then, what DOES the quote that Ronin posted mean?


Just because it is in a guru's guide, does not mean that it is right.
Ken Henderson usually knows his stuff, so it is a little surprising.
Then again, Ronin did not mention issue year or anything. This is an
area where things have changed over time. The statement might have been
true in 4.x. (I recall that it was documented that way. But when you
think of it, it does not make sense. TRUNCATE TABLE is just like DROP
TABLE, except that you keep the metadata.)

I looked up an old discussion in our internal MVP forum, and found
that at the time I had myself conducted a small experiment:

* Set "truncate log on checkpoint" to false.
* DUMP DATABASE
* TRUNCATE TABLE tbl1
* UPDATE tbl2 SET ... WHERE ...
* DUMP TRANSACTION
* LOAD DATABASE
* LOAD TRANSACTION

And this worked well. On SQL 6.5 I should add.

In the same thread I found a statement from an SQL Server dev who said
there is really only one command to break a backup/log chain and that is
ALTER DATABASE SET RECOVERY SIMPLE. (OK, so in SQL 2000 there is also
BACKUP TRANSACTION WITH TRUNCATE_ONLY/NO_LOG. But in SQL 2005, these
commands have no effect.) No DML or DDL on a single table can break
the log chain.


Hi Erland,

Ah, okay. Learned something new today! <g>

Thanks for the explanation!

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Nov 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ed | last post by:
I am trying to get some information to compare and contrast the Truncate Table function and the Drop Table function. I know that using Truncate Table is faster and saves the structure of the table...
3
by: martin | last post by:
Hi, We have a heavily used production server and a table which logs every hit on a web site. This table has grown large over time and we want to clear it down as efficiently as possible. We would...
3
by: LineVoltageHalogen | last post by:
Greeting All, I have a stored proc that dynamically truncates all the tables in my databases. I use a cursor and some dynamic sql for this: ...... create cursor Loop through sysobjects and...
2
by: rdraider | last post by:
Hi, I am trying to create a script that deletes transaction tables and leaves master data like customer, vendors, inventory items, etc. How can I use TRUNCATE TABLE with an Exists? My problem is...
9
by: Sumanth | last post by:
Are there any implementations of truncate in db2. Is it going to be implemented in the future? Is there an alternate way of doing a truncate of a table that has a high record count without using...
6
by: pramod | last post by:
Hi I know we can truncate a table in DB2 by first creating it with NOT LOGGED INITIALLY option. and when we need to truncate it, run the following command alter table <table name> activate...
2
by: Neil | last post by:
Can one use Truncate Table on a linked server table? When I try it, I get a message that only two prefixes are allowed. Here's what I'm using: Truncate Table svrname.dbname.dbo.tablename
10
by: Troels Arvin | last post by:
Hello, Until this date, I believed that DB2 has no TRUNCATE TABLE command. But then I came across...
8
by: ananthaisin | last post by:
How to reduce the table size for any table while using truncate or delete statements. In oracle 8i it was truncating the storage space but in 10g it is not .... I have given truncate statement in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.