views:

136

answers:

4

Hey guys i wanted to know, will i run into any concurrency problem with this? This is NOT in a transaction. This code is for Sqlite(prototype), but i plan to use it with either MySql or a SQL from MS

                command.CommandText =
                    "UPDATE tag_name SET count = count+1 "+
                    "WHERE tagid=@tagid";
                command.Parameters.Add("@tagid", DbType.Int64).Value = tagId;
                command.ExecuteNonQuery();
+4  A: 

I may be wrong, but I don't think you would have a problem; the tag_name table I would think would be locked while the UPDATE occurs, so that any other updates waiting to be executed would essentially be queued up rather than occurring concurrently.

Darth Continent
+4  A: 

No this shouldn't be a problem. By default the locking mechanism should take care of any concurrency issues in single statements.

rein
+2  A: 

I don't think so, I vaugely remember seeing something like this in a SQL server best practices example from Microsoft.

Paul
+2  A: 

not a problem You will have implicit transaction anyway. So it should not be a problem.

Even if you change TRANSACTION ISOLATION LEVEL, it should work just fine, at least on SQLServer.

van