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
  • Willie Singleton
    Jun, 2024 28

    The output of the SELECT * FROM Employees query will be all 10 records from the Employee table. The TRUNCATE TABLE Employees command removes all records from the table, but since it is wrapped between BEGIN TRAN and ROLLBACK, the truncation is not committed. The ROLLBACK command undoes the truncation, leaving the table in its original state with all 10 records intact.

    This Post Was Last Modified: 10-06-2024, 09:18 Pm By Slice Masters

    • 0
  • Charlie Hubbard
    Jun, 2024 25

    To determine the output of the query, we need to analyze the query itself and the typical behavior of SQL queries involving aggregation functions like COUNT() without a GROUP BY clause basketball stars.

    Assuming the query in question is:

    1. SELECT COUNT(*) FROM Employee;

    Here’s what this query does:

    • It selects the count of all rows (COUNT(*)) from the Employee table.
    • Since there is no GROUP BY clause, the COUNT(*) function will aggregate all rows in the table into a single result.

    Given that the Employee table has 10 records, the output of the query will simply be the count of those records, which is 10.

    Therefore, the output of the query SELECT COUNT(*) FROM Employee; will be: 10
    This result represents the total number of rows in the Employee table.

    • 0
  • 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