Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. RollBack Process

RollBack Process

Scheduled Pinned Locked Moved Database
databasesql-serversysadminquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hello Everybody, Is it possible to Rollback Table in SQL Server 2005 if it is Truncated? Thanks

    If you can think then I Can.

    R W 2 Replies Last reply
    0
    • L Lost User

      Hello Everybody, Is it possible to Rollback Table in SQL Server 2005 if it is Truncated? Thanks

      If you can think then I Can.

      R Offline
      R Offline
      R Giskard Reventlov
      wrote on last edited by
      #2

      No: see here: TRUNCATE TABLE (Transact-SQL)[^]. From the page: "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 data and records only the page deallocations in the transaction log."

      "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

      1 Reply Last reply
      0
      • L Lost User

        Hello Everybody, Is it possible to Rollback Table in SQL Server 2005 if it is Truncated? Thanks

        If you can think then I Can.

        W Offline
        W Offline
        Wendelius
        wrote on last edited by
        #3

        Hi, If you mean that can you rollback the truncation of a table if it's done in a tranaction: Yes. You can test this with a small test case:

        -- Table creation and filling
        CREATE TABLE TruncTest (
        Column1 int);

        BEGIN
        DECLARE @cnt INT;
        SET @cnt = 0;
        WHILE @cnt < 100 BEGIN
        INSERT INTO TruncTest VALUES (@cnt);
        SET @cnt = @cnt + 1;
        END;
        END;

        SELECT COUNT(*) AS Rows FROM TruncTest;

        -- Result:
        -- Rows
        -- 100

        --test truncation
        BEGIN TRANSACTION;
        TRUNCATE TABLE TruncTest;
        SELECT COUNT(*) AS Rows FROM TruncTest;

        -- Result:
        -- Rows
        -- 0

        ROLLBACK;

        SELECT COUNT(*) AS Rows FROM TruncTest;

        -- Result:
        -- Rows
        -- 100

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups