Instead of COUNTING ROWS, you need to get the MAX value from the table for this field / column, here, in accordance with the given values, it is 11, and then increase it by +1.
So you need to use the following code in the code,
Select Max(Key Field) + 1 from [table name]//this will give you new key value i.e. 12
I suggest you use the Identity column, so you don’t have to worry about raising the primary key values.
source
share