Can SQL Server have an identity column based on another column?
I have a table design like this
Audit
AuditId
CompanyId
Everything in the system is audited, and the table can be multi tenant, thus the CompanyId
.
In the context of an audit, people like to see a sequential sequence of events and due to the multi tenant nature, the identity will skip numbers like this.
- Company1 User logged in
- Company1 User logged out
- Company1 User logged in
- Company9 User logged in
- Company1 User logged out
- Company9 User logged out
I would ideally keep AuditId
as a normal identity but wish to have a secondary identity column that is unique to CompanyId
.
Is this possible in SQL Server, or do I need to do it in code?