What I want to do is have a table structure like this:
TypeID int not null (foreign key)
ItemID int (computed value +1 for each value with same TypeId)
Data string
e.g.
TypeId ItemId Data
1 1 "some data"
1 2 "some data"
2 1 "some data"
3 1 "some data"
3 2 "some data"
If I have computed columns as a key, am I going to have issues with concurrency as opposed to identity columns?
The
ItemIdcolumn seems to be the result of aROW_NUMBER OVER(PARTITION BY TypeID)(see the docs) — is that how you’re computing it? As such it’s not really suitable as part of a key due to concurrency issues (two transactions inserting rows with the sameTypeID, as you mention). But what does that have to do with “how to increment a subset”? What subset of what? And what’s your question? Why not just make something else the key instead (typically an artificial auto-increment column)?