kazinix
kazinix

Reputation: 30153

TSQL/.NET - Should one use SqlTransaction when retrieving data?

As far as I know, we use SqlTransaction to enable rollback if a statement in a batch of commands fails. My question is, is it necessary to use SqlTransaction when retrieving data/using select statements?

Upvotes: 1

Views: 138

Answers (2)

DevDelivery
DevDelivery

Reputation: 447

No, it is not necessary. Each Sql statement has an implicit transaction. But it can be useful if either the default transaction is not optimal - such as a Read Uncommitted would be better - or if you have multiple reads and you want the data to be consistent - such as separate statements for the summary and detail and you want the detail to add up to the summary.

Upvotes: 3

Icarus
Icarus

Reputation: 63970

No, there's no need to do this. Transactions are only needed if you want to recover from error on an insert/update/delete operation. If you can't read something, tough luck, but data integrity won't be affected.

Upvotes: 1

Related Questions