SQL Server unique auto-increment column in the context of another column
问题 Suppose the table with two columns: ParentEntityId int foreign key Number int ParentEntityId is a foreign key to another table. Number is a local identity, i.e. it is unique within single ParentEntityId . Uniqueness is easily achieved via unique key over these two columns. How to make Number be automatically incremented in the context of the ParentEntityId on insert? Addendum 1 To clarify the problem, here is an abstract. ParentEntity has multiple ChildEntity , and each ChiildEntity should