Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Non Logged Operations

Author  Topic 

The Enigma
Posting Yak Master

179 Posts

Posted - 2004-02-04 : 14:09:56
http://www.sqljunkies.com/weblog/enigma/posts/949.aspx Need your comments on the same .

Enigma

MichaelP
Jedi Yak

2489 Posts

Posted - 2004-02-04 : 14:37:52
I know that TRUNCATE TABLE is a non-logged operation. That's why it's so fast. I think that BULK INSERT (or is ti BCP?) is non-logged as well.

Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-04 : 14:38:17
I get Page Not Found



Brett

8-)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-02-04 : 14:44:52
Brett remove the period at the end of the URL.

Tara
Go to Top of Page

The Enigma
Posting Yak Master

179 Posts

Posted - 2004-02-04 : 14:45:33
quote:
Originally posted by MichaelP

I know that TRUNCATE TABLE is a non-logged operation. That's why it's so fast. I think that BULK INSERT (or is ti BCP?) is non-logged as well.

Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>



See this post http://www.dbforums.com/t981228.html

Enigma
Go to Top of Page

The Enigma
Posting Yak Master

179 Posts

Posted - 2004-02-04 : 14:46:13
Brett .. try going on to the SQLjunkies.com site and from there to my blog
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-04 : 15:07:37
EDIT2:

[so many scrubs, so little time]
Well you can't roll a bcp back....
[/so many scrubs, so little time]


USE Northwind
GO

DECLARE @ServerName sysname
, @User varchar(25)
, @Password varchar(25)
, @cmd varchar(8000)

SELECT @ServerName = ''
, @User = ''
, @Password = ''

SELECT @cmd = 'bcp Northwind.dbo.Orders out c:\Orders_20040204.dat -n -S'
+@ServerName+' -U'+@User+' -P'+@Password
SELECT @cmd = 'master..xp_cmdshell ' + '''' + @cmd + ''''
SELECT @cmd
EXEC(@cmd)

EXEC master..xp_cmdshell 'Dir C:\*.*'

BEGIN TRAN
SELECT * INTO NewOrders FROM Orders WHERE 1=0
COMMIT TRAN

SELECT COUNT(*) As ComittedCount FROM NewOrders

BEGIN TRAN
SELECT @cmd = 'bcp Northwind.dbo.NewOrders in c:\Orders_20040204.dat -n -S'
+@ServerName+' -U'+@User+' -P'+@Password
SELECT @cmd = 'master..xp_cmdshell ' + '''' + @cmd + ''''
SELECT @cmd
EXEC(@cmd)
-- oops
-- COMMIT TRAN
ROLLBACK TRAN

SELECT COUNT(*) AS Rollback_Count FROM NewOrders
GO

DROP TABLE NewOrders
EXEC master..xp_cmdshell 'DEL c:\Orders_20040204.dat'
EXEC master..xp_cmdshell 'Dir C:\*.*'
GO


Brett

8-)


EDIT: Or is in the context of the program itself...which seem more likely...if the bcp fails I would think it would "ROLLBACK"

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-04 : 15:17:42
And I didn't think you could ROLLBACK a TRUNCATE


USE Northwind
GO

BEGIN TRAN
SELECT * INTO NewOrders FROM Orders
COMMIT TRAN
SELECT COUNT(*) AS Created_Count FROM NewOrders
BEGIN TRAN
TRUNCATE TABLE NewOrders
ROLLBACK TRAN
SELECT COUNT(*) AS RollBack_Count FROM NewOrders
GO

DROP TABLE NewOrders
GO




Brett

8-)

EDIT:

[What a scrub]

quote:

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 just marks the page, becuause it doesn't have to worry about which pages to make...

[/What a scrub]

Go to Top of Page

The Enigma
Posting Yak Master

179 Posts

Posted - 2004-02-04 : 15:19:04
From Books online
When using the full recovery model, all row-insert operations performed by bcp are logged in the transaction log. For large data loads, this can cause the transaction log to fill rapidly. To help prevent the transaction log from running out of space, a minimally logged bulk copy can be performed if all of these conditions are met:

The recovery model is simple or bulk-logged.


The target table is not being replicated.


The target table does not have any triggers.


The target table has either 0 rows or no indexes.


The TABLOCK hint is specified. For more information, see Controlling the Locking Behavior.
Any bulk copy into an instance of Microsoft® SQL Server™ that does not meet these conditions is logged
Go to Top of Page

The Enigma
Posting Yak Master

179 Posts

Posted - 2004-02-05 : 10:49:45
quote:
Originally posted by MichaelP

I know that TRUNCATE TABLE is a non-logged operation. That's why it's so fast. I think that BULK INSERT (or is ti BCP?) is non-logged as well.

Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>



use northwind
go
exec SP_HELPINDEX EMPLOYEES
go
begin tran
CREATE nonclustered INDEX IDX_Employee_Title on Employees(Title)
exec SP_HELPINDEX EMPLOYEES
rollback tran
go
exec SP_HELPINDEX EMPLOYEES
go
USE pubs
GO
begin tran
DECLARE @ptrval binary(16)
SELECT @ptrval = TEXTPTR(pr_info)
FROM pub_info pr, publishers p
WHERE p.pub_id = pr.pub_id
AND p.pub_name = 'New Moon Books'
UPDATETEXT pub_info.pr_info @ptrval 0 0 'This One '
select pr.* FROM pub_info pr, publishers p
WHERE p.pub_id = pr.pub_id
AND p.pub_name = 'New Moon Books'

rollback tran
GO
select pr.* FROM pub_info pr, publishers p
WHERE p.pub_id = pr.pub_id
AND p.pub_name = 'New Moon Books'
go


CREATE TABLE [authors2] (
[au_id] [id] NOT NULL ,
[au_lname] [varchar] (40) NOT NULL ,
[au_fname] [varchar] (20) NOT NULL ,
[phone] [char] (12) NOT NULL CONSTRAINT [DF__authors__phone__1923BF5C] DEFAULT ('UNKNOWN'),
[address] [varchar] (40) NULL ,
[city] [varchar] (20) NULL ,
[state] [char] (2) NULL ,
[zip] [char] (5) NULL ,
[contract] [bit] NOT NULL ,
) ON [PRIMARY]
GO

exec master..xp_cmdshell 'bcp pubs.dbo.authors out c:\new_auth.dat -c -T'

go
begin tran
select count(*) from authors2
BULK INSERT pubs.dbo.authors2 FROM 'c:\new_auth.dat'
select count(*) from authors2
rollback tran

select count(*) from authors2


Here you go .. seems everything can be rolled back
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-05 : 10:52:58
Where's the bcp IN?

I couldn't get that to roll back....



Brett

8-)
Go to Top of Page

The Enigma
Posting Yak Master

179 Posts

Posted - 2004-02-05 : 11:00:42
I would argue that somehow "bcp in" is in a seperate session and it commits before returning back the control to SQL Server
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-05 : 12:06:34
quote:
Originally posted by The Enigma

I would argue that somehow "bcp in" is in a seperate session and it commits before returning back the control to SQL Server



I would think (hey you never know when that could happen) that that's true...AND rollback if the bcp fails...



Brett

8-)
Go to Top of Page

The Enigma
Posting Yak Master

179 Posts

Posted - 2004-02-05 : 12:50:21
So ... Is it right to declare that there exists no such thing as a non-logged operation in SQL Server. As rdjabarov sums it up on http://www.dbforums.com/t981228.html

quote:

In this light, I believe that "Non-Logged operation" is actually a minimally logged operation in reality, which means that its affects are viewed by the server on the page/segment level, rather than on the record level (I am not sure if it makes sense.)

So I guess I DON'T stay corrected in regards to Steve Duncan's comment that "TRUNCATE is a logged operation" simply because it's...minimally logged operation! Yes, it can be rolled back, but not in a row-by-row fashion. It can also be seen by Log Explorer, where you would not see individual DELETEs when trying to reverse this statement.

This is just to "set the record straight!"

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-05 : 14:44:39
So do you think the following is rolling back the CREATE TABLE for the statement only since it doesn't "see" the rows...


BEGIN TRAN
SELECT * INTO NewOrders FROM Orders
ROLLBACK TRAN
SELECT * FROM NewOrders






Brett

8-)
Go to Top of Page

The Enigma
Posting Yak Master

179 Posts

Posted - 2004-02-05 : 15:26:48
quote:
Originally posted by X002548

So do you think the following is rolling back the CREATE TABLE for the statement only since it doesn't "see" the rows...


BEGIN TRAN
SELECT * INTO NewOrders FROM Orders
ROLLBACK TRAN
SELECT * FROM NewOrders


Brett

8-)



(830 row(s) affected)

Server: Msg 208, Level 16, State 1, Line 1
Invalid object name 'NewOrders'.

What are you trying to point out ???
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-05 : 15:47:12
That even though it's a non logged operation (for the rows, I'm guessing)...the Creation of the table is logged and rolled back...



Brett

8-)
Go to Top of Page

The Enigma
Posting Yak Master

179 Posts

Posted - 2004-02-05 : 15:57:53
There is a difference between no-logged and minimally logged ... and i did not find the term non-logged in the Holy Book
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-03-29 : 11:46:37
quote:
Originally posted by The Enigma

There is a difference between no-logged and minimally logged ... and i did not find the term non-logged in the Holy Book



I found one! Look at CREATE TRIGGER

quote:


A TRUNCATE TABLE statement is not caught by a DELETE trigger. Although a TRUNCATE TABLE statement is, in effect, a DELETE without a WHERE clause (it removes all rows), it is not logged and thus cannot execute a trigger. Because permission for the TRUNCATE TABLE statement defaults to the table owner and is not transferable, only the table owner should be concerned about inadvertently circumventing a DELETE trigger with a TRUNCATE TABLE statement.






Brett

8-)
Go to Top of Page

The Enigma
Posting Yak Master

179 Posts

Posted - 2004-03-30 : 02:21:51
Again the same thing ... Its the pages that are logged in case of Truncate table ... and not the rows
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-03-30 : 09:11:23
I knooooooooooooooow (Ray Romano ref)

It's the BOL reference that say it's not logged....

quote:

A TRUNCATE TABLE statement is not caught by a DELETE trigger. Although a TRUNCATE TABLE statement is, in effect, a DELETE without a WHERE clause (it removes all rows), it is not logged and thus cannot execute a trigger. Because permission for the TRUNCATE TABLE statement defaults to the table owner and is not transferable, only the table owner should be concerned about inadvertently circumventing a DELETE trigger with a TRUNCATE TABLE statement.






Brett

8-)
Go to Top of Page
    Next Page

- Advertisement -