Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script-Migration for SQL Server does not script transactions correctly #34841

Open
rbonomo opened this issue Oct 7, 2024 · 0 comments
Open
Labels
area-migrations closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported regression type-bug
Milestone

Comments

@rbonomo
Copy link

rbonomo commented Oct 7, 2024

Script-Migration for SQL Server tries to wrap all operations in a transaction, but also runs GO after every operation within the transaction, which is the issue. Each operation should not have GO after it when everything is wrapped in a transaction. The transaction is not processed correctly because of the GO commands.

_No, you cannot use the GO statement inside a transaction in T-SQL because GO is not a T-SQL command itself. It is a batch separator used by client tools like SQL Server Management Studio (SSMS) and SQLCMD to separate blocks of code to be sent to the server in separate batches. When SQL Server encounters GO, it treats the preceding block of code as a complete batch and sends it to the server for execution.

Once you use GO, the transaction is automatically committed if it was open and has not been rolled back. If you try to use GO within a transaction block, it will split the transaction, and the server will process the batches independently.

To keep a transaction intact, you should avoid using GO and instead execute the entire transaction as a single batch without batch separators._

BEGIN TRANSACTION
    -- Some transactional statements
GO  -- Invalid use of GO in a transaction
    -- More transactional statements
COMMIT
@AndriySvyryd AndriySvyryd self-assigned this Oct 8, 2024
@AndriySvyryd AndriySvyryd added this to the 9.0.0 milestone Oct 8, 2024
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 10, 2024
@AndriySvyryd AndriySvyryd removed their assignment Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-migrations closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported regression type-bug
Projects
None yet
Development

No branches or pull requests

2 participants