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 «««56789»»»

Truncate rollback Expand / Collapse
Author
Message
Posted Thursday, April 22, 2010 10:27 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: 2 days ago @ 3:20 PM
Points: 18,064, Visits: 16,099
Steve Jones - Editor (4/22/2010)
I think this was worded a little poorly, and I didn't catch the insert issue. I ran the code on 2008, it worked, I let the question go. I thought the rollback/truncate was tricky enough to be worth 2 points.

I have added 2008 to the question header, as well as noted in the answer for error, "error on the last SELECT".

The debate is interesting here, but for those of you that say that the question isn't fair because it's 2008 specific, 2008 isn't even the current version today. SQL Server 2008 R2 is. I would think that after a year and a half, that you would expect that 2008 is the subject of most questions.

SQL 2000 is EOL, SQL 2005 is getting close to a complete end of support (it's 2010), regardless of what's in *your* environment, consider 2008 to be the standard.


Thanks for clearing all that up Steve.




Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Post #908824
Posted Thursday, April 22, 2010 10:28 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 8:46 AM
Points: 5,676, Visits: 6,488
The person who posted the question should have specified environment. I didn't have to run the code to know the VALUES statement wouldn't work in 2005. Therefore, I chose "Error" even though the Error answer was wrong. EDIT - I thought there was a typo in the last answer. It's happened before.

I was tempted to choose 3, but couldn't figure out how the VALUES statement would work. If I'd known what edition, it would have changed the way I read the question.


Brandie Tarvin, MCITP Database Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #908826
Posted Thursday, April 22, 2010 10:28 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: 2 days ago @ 3:20 PM
Points: 18,064, Visits: 16,099
Trey Staker (4/22/2010)

I got the question wrong. I'm kicking myself because it is something I should have gotten right, I just clicked the wrong box and hit submit before I had a chance to change it, noticed it right as I hit the button. doh.


It has happened to me too - I hate it when that happens.




Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Post #908827
Posted Thursday, April 22, 2010 10:53 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, December 17, 2014 4:44 AM
Points: 230, Visits: 852
CirquedeSQLeil (4/22/2010)
Hugo makes a great point. If everything is explicitly laid out so as to invoke no thought, then the question may be too easy and far too few will learn anything at all.
Also, since these QODs are more of a learning opportunity and community involvement opportunity, they are no less perfect than certification questions.


Yep he does and as I stated in my response completely explicit is one thing but specifying the important basics should always be done as that rarely detracts from the question.

Anyway time to move on to the next question I'm going to get wrong
Post #908851
Posted Thursday, April 22, 2010 10:58 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: 2 days ago @ 3:20 PM
Points: 18,064, Visits: 16,099
Ian Elliott (4/22/2010)
CirquedeSQLeil (4/22/2010)
Hugo makes a great point. If everything is explicitly laid out so as to invoke no thought, then the question may be too easy and far too few will learn anything at all.
Also, since these QODs are more of a learning opportunity and community involvement opportunity, they are no less perfect than certification questions.


Yep he does and as I stated in my response completely explicit is one thing but specifying the important basics should always be done as that rarely detracts from the question.

Anyway time to move on to the next question I'm going to get wrong






Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Post #908858
Posted Thursday, April 22, 2010 1:20 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Thursday, November 27, 2014 4:23 AM
Points: 20,584, Visits: 9,624
David_Simpson (4/22/2010)

If you really need the points... you can have mine. I've tried spending them at Walmart but they wouldn't take them.

Speaking of learning something, Paul Randal has some great articles on what happens during a TRUNCATE statement on his blog.

http://www.sqlskills.com/BLOGS/PAUL/post/A-SQL-Server-DBA-myth-a-day-%281930%29-TRUNCATE-TABLE-is-non-logged.aspx
http://www.sqlskills.com/BLOGS/PAUL/post/Search-Engine-QA-10-When-are-pages-from-a-truncated-table-reused.aspx

David






Thanks for the links... I'm sure many of us need to read this.
Post #908948
Posted Thursday, April 22, 2010 7:24 PM
SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Monday, August 18, 2014 4:04 AM
Points: 176, Visits: 567
I am politely disagreeing with statement that 'SQL 2008 is the standard'.

Shouldn't it be the standard(s) we have (note I am using "we"), are those of what our members are using?

I also understand it may not be optimal to have to two SQL versions in your computers, even if one is running in a virtual machine. It will only be by force or migration work to have two versions.

I also understand the difficulty of people making QoDs. In my workplace, I too have difficult people.

Just to add something useful, I hope, I am humbly posting a workaround:

if right(left((SELECT @@VERSION), 25), 4) = '2008'
select '2008'
--insert into a (b) values (1), (2), (3)

if right(left((SELECT @@VERSION), 25), 4) = '2005'
begin
select '2005'
--insert into a (b) values (1)
--insert into a (b) values (2)
--insert into a (b) values (3
end
else
select '6.5?'


I do believe a lot of you can make it better.
Post #909115
Posted Friday, April 23, 2010 5:42 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Sunday, June 6, 2010 6:47 AM
Points: 56, Visits: 24
Open Minded (4/22/2010)
I am politely disagreeing with statement that 'SQL 2008 is the standard'.

Shouldn't it be the standard(s) we have (note I am using "we"), are those of what our members are using?

I also understand it may not be optimal to have to two SQL versions in your computers, even if one is running in a virtual machine. It will only be by force or migration work to have two versions.

I also understand the difficulty of people making QoDs. In my workplace, I too have difficult people.

Just to add something useful, I hope, I am humbly posting a workaround:

if right(left((SELECT @@VERSION), 25), 4) = '2008'
select '2008'
--insert into a (b) values (1), (2), (3)

if right(left((SELECT @@VERSION), 25), 4) = '2005'
begin
select '2005'
--insert into a (b) values (1)
--insert into a (b) values (2)
--insert into a (b) values (3
end
else
select '6.5?'


I do believe a lot of you can make it better.



haha... it was a nice one at 6.5? ha ha


- Swaroop R -
Post #909345
Posted Friday, April 23, 2010 5:53 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Sunday, June 6, 2010 6:47 AM
Points: 56, Visits: 24
Ninja's_RGR'us (4/22/2010)
David_Simpson (4/22/2010)

If you really need the points... you can have mine. I've tried spending them at Walmart but they wouldn't take them.

Speaking of learning something, Paul Randal has some great articles on what happens during a TRUNCATE statement on his blog.

http://www.sqlskills.com/BLOGS/PAUL/post/A-SQL-Server-DBA-myth-a-day-%281930%29-TRUNCATE-TABLE-is-non-logged.aspx
http://www.sqlskills.com/BLOGS/PAUL/post/Search-Engine-QA-10-When-are-pages-from-a-truncated-table-reused.aspx

David






Thanks for the links... I'm sure many of us need to read this.






yep.. i thought that 'truncate' would never rollback. That was the way i was taught in past. You proved that wrong for me now. Thanks for the support links... Really, they helped me a lot and it added value to me when i discussed this Myth point with my friends..


- Swaroop R -
Post #909352
Posted Friday, April 23, 2010 8:55 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 8:46 AM
Points: 5,676, Visits: 6,488
SwaroopRaj (4/23/2010)

yep.. i thought that 'truncate' would never rollback. That was the way i was taught in past. You proved that wrong for me now.


The thing that trips most people up is the concept that Truncate is "not logged." I hear this concept a lot in discussions and in job interviews. And while it's broadly correct when answering the standard "Why is a Truncate better than a Delete" interview question, it's technically a wrong assumption.

Truncates are *minimally logged* (EDIT: in ALL database Recovery models), like having your database in Bulk-Logged Recovery Model. That means there are pointers to the pages of the just removed data that can yank that stuff back if needed.

Deletes are logged more than Truncates, (EDIT: being fully logged in FULL mode down to the row) even in Bulk-Logged mode, because I think (and I could be wrong here) the pointers are more finite, pointing to the actually extents instead of the pages.

So, yes, a Truncate can absolutely be rolled back. In fact, I'd be hard pressed to say what data change (not schema change) couldn't be rolled back at all.


Brandie Tarvin, MCITP Database Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #909555
« Prev Topic | Next Topic »

Add to briefcase «««56789»»»

Permissions Expand / Collapse