Skip to main content

Roll back truncate command

How many times it has happened that somebody asks u a difference of Truncate and Delete,Atleast i am the person who used to say the very first point is that "TRUNCATE CAN NOT BE ROLLED BACK" untill i came across the blog post of Pinal Dave

So,the best way to understand any point is start with sample,here what we will do is we will create one table and we will create one transaction and under which we will be doing our truncate thing...and finally we will observe the result

Lets us start it by creating sample table and our transaction like following as shown below


CREATE TABLE temp (Name varchar(50))
INSERT INTO temp SELECT 'Moe'
INSERT INTO temp SELECT 'Larry'
INSERT INTO temp SELECT 'Curley'


BEGIN TRAN
   SELECT * FROM temp
   TRUNCATE TABLE temp
   SELECT * FROM temp
ROLLBACK TRAN
   SELECT * FROM temp
   
DROP TABLE temp


Now if you just copy and paste this above in your query editor and hit F5 (RUN),you would be surprise to see that even if you have performed TRUNCATE operation on your table,your data are still available at the end of transaction if we ROLLBACK

I was also got the feeling of learning something new with this helpful post by Pinal,which inspired me to write this post,so that we can use it for further reference

i hope this post is larning for you people as well

comments are welcomed...:-D

Comments

  1. @Daivagna,

    this was really strange behavior.

    I couldn't digest the fact tht values are being retrieved even after truncate.

    thanx a lot 4 sharing this strange but correct information.

    keep it up...

    ReplyDelete
  2. wow mind boggling..
    i searched on google for these kind of Example but i did not get...
    after i saw it i could understand real use of Roll back practically...

    thanks sir.....

    ReplyDelete

Post a Comment

Popular posts from this blog

Why SitecoreAI - Getting into the shoes of the customer how to select right CMS

Hi Team, Lately, I have been talking to lot of our customers / potential customers and having pre-sales demos where one question always comes is "Why Sitecore" ?  Now this question can be for any product which is out for sell. And as a technician I always get into product technical features, but at the same time as a pre-sales guy, it also makes me think, surely all competitive products have same features, so definitely answer to this is not in the technicalities.  If you step back and think, we are also a customer in our daily life and buy lot of things, what is that process we go through? When we buy, how can your customer decide if this is a right fit for you or not, why we select A over B? Is it price? is it service? Is it a brand? Is it about features? Is it about brand loyalty?  When it is a technical product, I am sure it cannot start with the technicalities of the product or selecting product itself, 100% not, I feel decision is always business strategy first and ...

Hell of sitecore aliases pipeline breaking the site with 500 error

Hello Friends, I belive this blog post is very important for everyone because, It has some very serious effect on working of your headless website, i will share my experience what we faced and how we resolved it Issue we started facing Our site started giving "Key cannot be null or empty" with YSOD like following  Side affect Because of this 500 error, Our site pages were showing 500 custom error page intermittently and our MAU (Monthly Active User) drop rate increased. Sitecore KB There is already Sitecore KB article talking about this error but the patch which is provided on this link is confusing as well as very huge and it could bring other issues along with it as that upgrade patch also has lot of other things too which i did not want to introduce in our stable CMS. Known Issues - Retrieving the child items of resource items is not thread-safe Observation Though the surfaced exception was looking similar and giving same error and behavior given on this article, We looked...

401.1 Unauthorized with windows authentication error code 0xc000006d

How many of you have faced this hosting issue when you do everything what it takes to run the site with windows authentication but still you are getting the same error again and again? If you think you also have faced the same issue and you tired of reading MSDN KBs for it and still have not found the issue (If KB has solved the issue, well and good, if not you can try this trick),Please Read below Typical scenario In typical hosting with IIS, i did every possible things like enabling windows authentication, changing it in web.config, configuring connection pool, authorization rules, it asks me for window authentication login and despite of entering correct credentials it always fails and keeps on asking for login, and when pressed cancel it gives 401.1 with 0xc000006d error code Solution (Which worked for me at-least after trying for almost 6-9 hrs) You need to change the Loop Back Check in registry so that it allows the host names which you are giving in url are allowed and au...