Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 44434

A mechanism for committing a consistent set of changes into a database atomically.

13 votes
Accepted

Why can SELECT see updated row before commit?

Assuming the second SSMS window is using the default READ_COMMITTED isolation level, you will see the before value instead of being blocked by the uncommitted transaction if the database has the READ_COMMITTED_SNAPSHOT …
Dan Guzman's user avatar
  • 28.5k
0 votes
Accepted

Limit the number of votes

int NOT NULL , quantity int NOT NULL , CONSTRAINT PK_Vote PRIMARY KEY CLUSTERED (userId, contentId) ); GO CREATE PROC dbo.CastVote @userId int ,@contentId int AS SET NOCOUNT ON; SET TRANSACTION … If the more common case is that users will cast more than 2 votes , you could reverse the logic and update first: CREATE PROC dbo.CastVote @userId int ,@contentId int AS SET NOCOUNT ON; SET TRANSACTION
Dan Guzman's user avatar
  • 28.5k
2 votes
Accepted

MSSql bcp transaction rollback on error

A rollback of a BCP batch transaction occurs when SQL Server errors occur during the bulk insert (e.g. constraint violations) but not due to client side errors (e.g. data type conversion during BCP parsing … Erred records are not sent to the server and are not part of a transaction. SQL Server errors will not only rollback the current batch but abort the entire BCP operation. …
Dan Guzman's user avatar
  • 28.5k
3 votes
Accepted

The state of the MSSQL Options set during query after it ends

If you execute an explicit ad-hoc SET XACT_ABORT ON, the setting remains in effect for the duration of the current session. Other session settings will remain unchanged. In the case of SET XACT_ABOR …
Dan Guzman's user avatar
  • 28.5k
1 vote

SSIS Error :Cannot roll back .No transaction or savepoint of that name was found

The general best practice is to perform transaction management in either the client application (SSIS), server-side T-SQL, but not both. … This technique helps avoid issues caused by long-running transactions, such as blocking and large transaction logs. …
Dan Guzman's user avatar
  • 28.5k
32 votes
Accepted

Is this an error in SQL Server's documentation for ROLLBACK?

The ROLLBACK TRANSACTION documentation is correct, albeit not clear without additional context. ROLLBACK is shorthand for the similar ROLLBACK WORK statement rather than ROLLBACK TRANSACTION. … Below is an excerpt from the ROLLBACK WORK doc page: ROLLBACK [ WORK ] [ ; ] This statement functions identically to ROLLBACK TRANSACTION except that ROLLBACK TRANSACTION accepts a user-defined transaction
Dan Guzman's user avatar
  • 28.5k
1 vote

Explicit transaction left open after try/catch

The transaction is left open as a result unless SET XACT_ABORT ON is specified. … BEGIN TRANSACTION; DELETE FROM Production.Product WHERE ProductID = 980; COMMIT TRANSACTION; END TRY BEGIN CATCH IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION; DECLARE …
Dan Guzman's user avatar
  • 28.5k
3 votes
Accepted

Difference in location of transaction isolation level declaration - inside/ouside a transact...

Below are relevant excerpts from the SET TRANSACTION ISOLATION LEVEL documentation. … Note that there is no mention of BEGIN TRANSACTION, COMMIT, etc. These transaction control statements do not affect the current session transaction isolation level. …
Dan Guzman's user avatar
  • 28.5k
4 votes
Accepted

Handling duplicate values using trigger

It's generally best to use stored procedures rather than triggers for business rules. Triggers are more appropriate to enforce data integrity rules in cases where declarative constraints can't be used …
Dan Guzman's user avatar
  • 28.5k
4 votes

Select into query, insert fails, but the table is created

In old versions of SQL Server, both operations were done in a single atomic transaction but this was notorious for locking system tables and causing excessive blocking. …
Dan Guzman's user avatar
  • 28.5k
4 votes

SQL SERVER: How to get the stored procedure text EXCLUDING comments?

command.ExecuteReader() while($reader.Read()) { $hasBeginTransaction = Test-HasBeginTrasaction -procText $reader["definition"] if( $hasBeginTransaction ) { Write-Host "Has BEGIN TRANSACTION … $hasSetXactAbortOn ) { Write-Host "Has BEGIN TRANSACTION without SET_XACT_ABORT ON: $($reader["ProcedureName"])" } } $reader.Close() $connection.Close() } catch { …
Dan Guzman's user avatar
  • 28.5k
6 votes

How SQL Server transaction works with log records

Normally, other sessions will be blocked (due to locking) or will see the original value before changes (due to row versioning) until the transaction is committed. … Transaction isolation levels, and their implementation, are not related to transaction durability. It doesn't matter when log and data file writes occur for isolations levels to behave properly. …
Dan Guzman's user avatar
  • 28.5k