Assuming
CREATE TABLE TableA
(
IntColumn INT NOT NULL PRIMARY KEY
)
INSERT INTO TableA VALUES (0)
is the following atomic? i.e. if multiple application threads execute the following, am I at risk of an eventual PK violation?
INSERT INTO TableA
VALUES ((SELECT MAX(IntColumn) FROM TableA) + 1)
Can you point me to any documentation about this? My google-fu failed…
[I’m aware of auto-incrementing columns, but that isn’t sufficient for what I’m actually doing.]
You flagged this question with SQL 2012. If that is your environment you can use the new sequence feature: http://msdn.microsoft.com/en-us/library/ff878091.aspx and http://msdn.microsoft.com/en-us/library/ff878370.aspx