Questions tagged [sqltransaction]

An SQL-transaction is a unit of work that is performed against a database. Transactions are units or sequences of work accomplished in a logical order. Executing SQL-statements in Transactions, can ensure data integrity and handle database errors.

An SQL-transaction is a unit of work that is performed against a database. Transactions are units or sequences of work accomplished in a logical order.

A transaction is the propagation of one or more changes to the database. For example, creating, updating, or deleting a record from the table. Transactions are used to ensure data integrity and to handle database errors, by collecting SQL queries into a group and executing all of them together, as one unit of work.

Properties of Transactions: Transactions have the following four standard properties, usually referred to by the acronym ACID:

  • Atomicity: ensures that all operations within the work unit are completed successfully; otherwise, the transaction is aborted at the point of failure, and previous operations are rolled back to their former state.
  • Consistency: ensures that the database properly changes states upon a successfully committed transaction.
  • Isolation: enables transactions to operate independently of and transparent to each other.
  • Durability: ensures that the result or effect of a committed transaction persists in case of a system failure.
233 questions
3
votes
1 answer

SQL Server - Registering user code to be run when a transaction completion is attempted

I have an SQL CLR Stored Procedure which registers an event handler for the completion of the current transaction [SqlProcedure] public static void MySProc() { Transaction.Current.TransactionCompleted += new…
Franco Tiveron
  • 2,364
  • 18
  • 34
3
votes
2 answers

Can a SQL "DELETE" statement followed by a "WHERE NOT IN" statement be in same transaction?

If I have the following SQL block (in SQL SERVER 2008 R2): BEGIN BEGIN TRAN DELETE FROM dbo.fooData WHERE LastUpdate < DateAdd(hour, -1,GETUTCDATE()) COMMIT BEGIN TRAN DELETE FROM dbo.barData WHERE SessionID NOT IN…
Brian
  • 203
  • 2
  • 3
  • 13
3
votes
3 answers

How to put these calls in a SqlTransaction?

I have a class with all my data access code in it for my ASP.NET 4.0 application. There are two methods in the class which insert data into the database. I want to enlist these inserts in a SqlTransaction and roll the transaction back if one of the…
Mark Allison
  • 6,838
  • 33
  • 102
  • 151
3
votes
1 answer

SQL Server: Replace Arabic Character in Select Statement

I would like to replace Arabic character in select statement with another Arabic character in SQL server, example query: select replace(ArabicName, 'أ', 'ا') as ArabicName from dataIndividual; But it does not replace, the reason probably that SQL…
Mohammad Anini
  • 5,073
  • 4
  • 35
  • 46
3
votes
1 answer

There's a way to find out if my row is read committed or read uncommitted?

I'm using a READ UNCOMMITTED transaction and I want to know if a specific row is committed or uncommitted.
Ricardo França
  • 2,923
  • 2
  • 18
  • 18
3
votes
3 answers

Single sql transaction on multiple method

Modular programing is right approach but it sometimes lead to problem which needs extra efforts and research. I have three database insert function like InsertName(),InsertAddress(),InsertPhoneNo() take it as example. All these functions must…
Hot Cool Stud
  • 1,145
  • 6
  • 25
  • 50
3
votes
3 answers

Finally Clause in SQL Server Transaction? Something that will execute irrespective of success or failure?

In SQL Server, is there something similar to finally clause in try..catch... block of c# ? I mean, I am using BEGIN TRAN, END TRAN, COMMIT TRAN, ROLLBACK TRAN etc in a SQL Server transaction and want a section or some set of actions that needs to…
3
votes
3 answers

How to handle multiple SQL transactions through different .net(c#) threads

I have the following method for bulk insert of the data in tables. First my code populates the data in data tables and inserts this data in corresponding tables using the SqlBulkCopy claas of the .net . I have requirement that data should get…
Sagar
  • 454
  • 10
  • 22
2
votes
1 answer

how to prevent convert big numbers as varchar example 1444092 is 1.44409e+006

this is my final query select Codigo, Indicador, case when Indicador like '%Porcentaje%' then cast((round((([Valor Censo Elegido]/@cantidad)*100),0)) as varchar(50))+' %' else cast([Valor Censo Elegido]as varchar(50)) end as [Valor Censo…
angel uc
  • 279
  • 2
  • 8
  • 21
2
votes
1 answer

SqlTransaction causing application crash on error?

Here's some background: Periodically our site will crash to the point of having to restart IIS; this almost always happens within an hour of patching a DLL (we use a Web Site project, not a Web Application project, so each ASPX page is a separate…
Wayne Molina
  • 19,158
  • 26
  • 98
  • 163
2
votes
2 answers

Keepalive sql transaction

I have a simple problem with sql transactions. I connect to my database in method A and start a sql transaction. At the end of the method I close the connection, because the calculation (external method) takes a long time. After finishing the…
CSchulz
  • 10,882
  • 11
  • 60
  • 114
2
votes
1 answer

SQL Check if exists before update

Hello All I would like to see an example how to check if pappssn exsist in database before the update is complete. If so to raise an error record exsist. My front end is VB however i would like to handle this within SQL in my stored procedure if…
Tim
  • 1,209
  • 4
  • 21
  • 33
2
votes
3 answers

Recursive/nested transaction

I have 2 store procedures A, B, both are in a transaction block. The problems is A calls B, so, there is recursive/nested transaction. I'm not sure is there problem? What will happen when I call A? Cited from "MySQL Stored Procedure…
Dagang
  • 24,586
  • 26
  • 88
  • 133
2
votes
3 answers

After truncate , we can not rollback data in SQL?

I have a table named a that has 26 rows: Select * from a Output is 26 Begin Tran Truncate table a Select * from a Output is zero rows Rollback Tran Select * from a Output is again 26 rows Truncate is ddl command we cannot perform rollback…
Ankush
  • 347
  • 2
  • 10
2
votes
0 answers

Return from method without committing transaction

Having the following code what would happen if I return from method without calling Commit() on the transaction object? var transaction = connection.BeginTransaction(); try { int val; var myCommand = new SqlCommand( @"SELECT…
bigb055
  • 198
  • 3
  • 14
1 2
3
15 16