We are creating a multi-user web application where they need a unique postId for the post they create. Each post has (userId, postId) as its primary primary key.
Currently postId is an identifier value, but because of the need to support some operations that require postId inserted as is (without re-numbering), we decided to use SET IDENTITY_INSERT ON/OFF .
However, our database administrator told us that such an operation is not intended for use by the application server, since the ALTER permission requirement is:
Access rights
The user must own the table or have ALTER permission in the table.
https://msdn.microsoft.com/en-ca/library/ms188059.aspx
If the application server is hacked, with ALTER permission, this looks pretty risky. Our database administrator suggests that we do not use the authentication value at all and locally generate a unique postId for each user.
Can SET IDENTITY_INSERT ON left globally?
If it cannot be left at the global level, avoids the identity value and uses the local generation postId (for each user) with max(postId)+1 for the user, does it make sense? We prefer to use the identity value, if possible, because we are worried about the possible deadlocks and performance issues associated with creating the PostId user generation.
sql-server web-applications sql-server-2012 database-design
Henry
source share