user3124029
user3124029

Reputation: 3

SQL Server: undo the last executed query with C#

Is there any algorithm or easy way to undo last executed query in SQL Server. I am using C# and I'0ve written a program integrated with SQL Server. Think like paint. When I press "ctrl + z" it gets back last operation.

Upvotes: 0

Views: 1396

Answers (1)

Tristan
Tristan

Reputation: 1024

The short answer is no, you can not.

As people have said in the comment the only way to undo changes in the past without any prepared way of undoing can only be undone by restoring a backup.

As to your comment about transactions locking tables, that is true. But any and all changes to the database are done by transactions. The only difference is implicit or explicit transactions which have the same end result.

So for all practical purposes this:

INSERT demo..employees (firstname,lastname)
VALUES ('Joe','Doe')

Does the same as this:

BEGIN TRANSACTION

    INSERT demo..employees (firstname,lastname)
    VALUES ('Joe','Doe')
    IF 1 = 1
    BEGIN
        ROLLBACK
        PRINT 'Undo'
    END
    ELSE COMMIT

Except ofcourse that the second block will Always rollback. Hope this helps and have fun!

Upvotes: 2

Related Questions