| 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> |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-02-04 : 14:38:17
|
| I get Page Not FoundBrett8-) |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-02-04 : 14:44:52
|
| Brett remove the period at the end of the URL.Tara |
 |
|
|
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.htmlEnigma |
 |
|
|
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 |
 |
|
|
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 NorthwindGODECLARE @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 @cmdEXEC(@cmd)EXEC master..xp_cmdshell 'Dir C:\*.*'BEGIN TRANSELECT * INTO NewOrders FROM Orders WHERE 1=0COMMIT TRANSELECT COUNT(*) As ComittedCount FROM NewOrdersBEGIN TRANSELECT @cmd = 'bcp Northwind.dbo.NewOrders in c:\Orders_20040204.dat -n -S' +@ServerName+' -U'+@User+' -P'+@Password SELECT @cmd = 'master..xp_cmdshell ' + '''' + @cmd + ''''SELECT @cmdEXEC(@cmd)-- oops-- COMMIT TRANROLLBACK TRANSELECT COUNT(*) AS Rollback_Count FROM NewOrdersGODROP TABLE NewOrdersEXEC master..xp_cmdshell 'DEL c:\Orders_20040204.dat'EXEC master..xp_cmdshell 'Dir C:\*.*'GO Brett8-)EDIT: Or is in the context of the program itself...which seem more likely...if the bcp fails I would think it would "ROLLBACK" |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-02-04 : 15:17:42
|
And I didn't think you could ROLLBACK a TRUNCATEUSE NorthwindGOBEGIN TRANSELECT * INTO NewOrders FROM OrdersCOMMIT TRANSELECT COUNT(*) AS Created_Count FROM NewOrdersBEGIN TRANTRUNCATE TABLE NewOrdersROLLBACK TRANSELECT COUNT(*) AS RollBack_Count FROM NewOrdersGODROP TABLE NewOrdersGO Brett8-)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] |
 |
|
|
The Enigma
Posting Yak Master
179 Posts |
Posted - 2004-02-04 : 15:19:04
|
| From Books onlineWhen 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 |
 |
|
|
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 goexec SP_HELPINDEX EMPLOYEESgobegin tran CREATE nonclustered INDEX IDX_Employee_Title on Employees(Title) exec SP_HELPINDEX EMPLOYEESrollback trangoexec SP_HELPINDEX EMPLOYEESgoUSE pubsGObegin tranDECLARE @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 tranGOselect pr.* FROM pub_info pr, publishers p WHERE p.pub_id = pr.pub_id AND p.pub_name = 'New Moon Books'goCREATE 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]GOexec master..xp_cmdshell 'bcp pubs.dbo.authors out c:\new_auth.dat -c -T'gobegin tran select count(*) from authors2 BULK INSERT pubs.dbo.authors2 FROM 'c:\new_auth.dat' select count(*) from authors2rollback transelect count(*) from authors2Here you go .. seems everything can be rolled back |
 |
|
|
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....Brett8-) |
 |
|
|
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 |
 |
|
|
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...Brett8-) |
 |
|
|
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.htmlquote: 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!"
|
 |
|
|
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 TRANSELECT * INTO NewOrders FROM OrdersROLLBACK TRANSELECT * FROM NewOrders Brett8-) |
 |
|
|
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 TRANSELECT * INTO NewOrders FROM OrdersROLLBACK TRANSELECT * FROM NewOrders Brett8-)
(830 row(s) affected)Server: Msg 208, Level 16, State 1, Line 1Invalid object name 'NewOrders'.What are you trying to point out ??? |
 |
|
|
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...Brett8-) |
 |
|
|
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 |
 |
|
|
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 TRIGGERquote: 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.
Brett8-) |
 |
|
|
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 |
 |
|
|
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.
Brett8-) |
 |
|
|
Next Page
|