I want to run this SQL Statement to insert a new rank to the Rank table. The primary key rank_id is a char field so its not auto incremented. So I use TOP keyword to get the last ID and then increment it in SQL.
const string InsertStatement = @"BEGIN DECLARE @ID INT = (SELECT TOP 1 (rank_id + 1) FROM Rank ORDER BY [rank].rank_id DESC)
INSERT INTO RANK (rank_id, rank_name, shift_rate, revised_date) VALUES (@ID, @rank, @rate, @date) END"
I think that I should handle this transaction to avoid dirty reads other wise another user might read a wrong ID as the last one. Am I correct? Then what is the correct isolation level for a this sort of situation? What about this...
using(var Trans = sqlConnection.BeginTransaction(IsolationLevel.Serializable))
IsolationLevel.ReadCommitted- RahulSerializable, or can he get away with something less restrictive (likeReadCommitted). - Lynn CrumblingData can be changed by other transactions between individual statements within the current transaction...What does it mean bycan be changed? - CAD