MSSQLTips.com - your daily source for SQL Server tips

Google
 
Web mssqltips.com

ESSENTIALS: Home | Tips | Search | Categories | Top 10 | Products | Authors | Blogs | Forums | Webcasts | Advertise | About
SQL Server T-SQL Interview Questions - MSSQLTips

MSSQLTips

MSSQLTips.com - your daily source for SQL Server tips
Welcome to MSSQLTips Sign in | Join | Help
in Search

SQL Server T-SQL Interview Questions

Last post 04-08-2008 3:26 AM by Bals. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 03-07-2008 12:30 AM

    SQL Server T-SQL Interview Questions

    This post is related to this tip: SQL Server T-SQL Interview Questions

    http://www.mssqltips.com/tip.asp?tip=1450

  • 03-07-2008 7:16 AM In reply to

    • aprato
    • Top 10 Contributor
    • Joined on 12-01-2007
    • Greater Boston
    • Posts 262

    Re: SQL Server T-SQL Interview Questions

    One thing about TRUNCATE.... truncate is actually a minimally logged command.  Page deallocations are recorded.  It's possibel to recover from a TRUNCATE if it's done quickly.

     Here's an example

     

    create table mytable (id int identity)
    go
    insert into mytable default values
    insert into mytable default values
    insert into mytable default values
    insert into mytable default values
    insert into mytable default values
    go
    begin tran tran1

    truncate table mytable

    rollback

    select * from mytable

  • 03-18-2008 2:40 AM In reply to

    • Bals
    • Top 75 Contributor
    • Joined on 03-18-2008
    • Madurai
    • Posts 3

    Re: SQL Server T-SQL Interview Questions

    no

    Regards
    BalaMurugan M R
    SQL Programmer
    Honeywell Technology Solutions
    India
  • 03-18-2008 1:09 PM In reply to

    • aprato
    • Top 10 Contributor
    • Joined on 12-01-2007
    • Greater Boston
    • Posts 262

    Re: SQL Server T-SQL Interview Questions

    Of course it can.  Page deallocations are recorded.

     From the 2005 BOL:

    ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/3d544eed-3993-4055-983d-ea334f8c5c58.htm 

    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.
     

    There's no guarantee it will work but if done quickly (like, right after the table is truncated as in the sample I supplied) it can actually be done. 

  • 04-04-2008 7:33 AM In reply to

    Re: SQL Server T-SQL Interview Questions

    aprato,

    Agreed TRUNCATE is a minimally logged operation as well as under the code scenario you provide and/or with vendor tool the data can be recovered. 

    Thank you for pointing out those items.

    Thank you,
    The MSSQLTips.com Team

    Filed under: ,
  • 04-08-2008 3:26 AM In reply to

    • Bals
    • Top 75 Contributor
    • Joined on 03-18-2008
    • Madurai
    • Posts 3

    Re: SQL Server T-SQL Interview Questions

    Aprato, Yeah Agreed . Thanks for your valuble info

    Regards
    BalaMurugan M R
    SQL Programmer
    Honeywell Technology Solutions
    India
Page 1 of 1 (6 items)