Maintaining Database Consistency with Transactions in .NET

Friday Jul 29th 2005 by Staff

While databases can efficiently hold and query large amounts of information, all that data is useless if its integrity is questionable. Transactions help ensure that a database's data remains consistent. This article examines how to wrap multiple SQL statements within an atomic database transaction using the SqlTransaction class in the System.Data.SqlClient namespace.

[From 4GuysFromRolla]

While databases can efficiently hold large amounts of information that can be queried, all that data and all that querying power is useless if the data is incorrect or nonsensical. Databases provide a plethora of techniques for ensuring the integrity and consistency: primary key and unique constraints can be employed to ensure entity integrity; foreign key constraints aid in ensuring relational integrity, and transactions help ensure that the database's data remains consistent.

While INSERT, UPDATE, and DELETE statements are the most granular operations for modifying a database's underlying data, at times we want to treat multiple INSERT, UPDATE, and/or DELETE statements as one atomic operation. That is, in certain situations, rather than having each INSERT, UPDATE, and DELETE statement stand on its own, we want the set of statements to be, together, an indivisible unit. When issuing this set of statements we want either the entire set of statements to succeed, or all to fail - there should be no 'in-between' state.

The article continues at

Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved