Rajeev Kumar
What will be the output of the below query, given an Employee table having 10 records?

BEGIN TRAN
TRUNCATE TABLE Employees
ROLLBACK
SELECT * FROM Employees

By Rajeev Kumar in .NET on Jul 07 2023
  • Pankaj Patel
    Jul, 2023 21

    Hi Rajeev Kumar,

    The output of the above query, gives 10 records of Employee table.

    TRUNCATE will not be affected as it is kept in between BEGIN TRAN and ROLLBACK block

    Hope this will help you!

    • 1
  • Rajeev Kumar
    Jul, 2023 10

    This query will return 10 records as TRUNCATE was executed in the transaction. TRUNCATE does not itself keep a log but BEGIN TRANSACTION keeps track of the TRUNCATE command.

    • 1
  • Praveen Mishra
    Jul, 2023 13

    The query you provided includes a transaction that truncates the “Employees” table and then rolls it back. Since the truncation is rolled back, the table will not be empty, and the SELECT statement will retrieve the records that were present before the truncation.

    Therefore, the output of the query will be the original records from the “Employees” table. The number of records retrieved will depend on the initial state of the table and the number of records it had before the transaction was executed.

    • 0
  • Uday Shankar
    Jul, 2023 10

    If we do select * from Employees we will find the 10 entries in the table. and after Truncate this will remove all of rows, and since after that immediately we are using rollback, this will revert all of the data and at the end the select satement will provide 10 entries, what it has initially.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS