You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add SQL Server write-safety instructions for T-SQL 🤖🤖🤖 - #5447
Standalone resubmission of #5310, revised per review.
No upstream or product links. The file stands on its own.
Dry run fails closed: anything other than an explicit 0, including NULL, is a dry run.
The procedure template archives in TOP (N) batches with one short transaction per batch, a fresh OUTPUT...INTO key set, and refuses to run inside a caller-owned transaction.
Removed the tooling, security, and review checklist sections that restated defaults. What remains is SQL Server-specific: XACT_ABORT with THROW, @@TRANCOUNT handling, statements that cannot run in a user transaction, batched archive-then-delete, and read-only DMV diagnostics.
The procedure template was executed on SQL Server 16.0.4305.5 Developer Edition (64-bit) against a 12,000-row test table: default dry run and @DryRun = NULL changed nothing, a caller transaction was refused, invalid parameters raised errors, a live run with @batchsize = 500 moved exactly the 4,000 qualifying rows, and a rerun moved 0.
Risk tier:merge-risk:medium — New or substantially changed resource without privileged execution Required to merge: passing submission-gate checks plus 1 approval from reviewers with write access.
Why this tier
Adds 1 file(s), e.g. instructions/sql-server-safe-tsql.instructions.md
HOLDLOCK gives this scan serializable semantics, so it can retain range locks beyond the copied rows and block inserts, including when the final batch is empty. UPDLOCK already protects copied rows until the key-based delete commits; remove HOLDLOCK unless preventing new qualifying rows is an explicit requirement.
Under row/key locking, a full 5,000-row batch can reach SQL Server's lock-escalation threshold, causing table-wide blocking until the batch commits. Use a smaller default such as 1,000 to reduce this risk; larger overrides should be tuned for the workload.
The reason will be displayed to describe this comment to others. Learn more.
Thanks @scottkcoffey-a11y — this addresses everything from #5310: no upstream link, @DryRun IS NULL OR @DryRun <> 0 fails closed, real TOP (@BatchSize) batches, and the generic sections are gone. The IMPLICIT_TRANSACTIONS check and the @RowsAffected-after-rethrow note are exactly the SQL Server traps this file should carry. Optional nit: a narrower .ps1 glob would help. Approving.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Standalone resubmission of #5310, revised per review.
The procedure template was executed on SQL Server 16.0.4305.5 Developer Edition (64-bit) against a 12,000-row test table: default dry run and @DryRun = NULL changed nothing, a caller transaction was refused, invalid parameters raised errors, a live run with @batchsize = 500 moved exactly the 4,000 qualifying rows, and a rerun moved 0.