I'm using SQL Server 2005 for the first time, having mostly worked with MySQL in the past. I'm used to using auto_increment to create unique IDs in tables.
Anyway... I'm working in a java app, and need to do the following. Presume my table has two columns: itemID (int) and itemValue(int).
This is basically what I want to do (the dbconn methods are just pseudocode):
dbconn.execSQL("begin tran");
int nextID = dbconn.execSQLSelect("select max(itemID)+1 from itemTable");
dbconn.execSQLInsert("insert into itemTable values " + nextID + ", 1000");
dbconn.execSQL("commit tran");
Will the begin/commit tran statements deal with the possible race condition between lines 2 and 3? Or is there some TSQL equivalent of MySQL's "lock table" that I need to do?