Below is my table Schema:
CREATE TABLE [dbo].[Sample](
[BoardId] [int] IDENTITY(1,1) NOT NULL,
[UserCode] [nvarchar](20) NOT NULL,
[Desc] [nvarchar](100) NOT NULL,
[Version] [int] NOT NULL,
[ParentId] [int] NULL,
[CreatedOn] [datetime] NOT NULL,
[ModifiedOn] [datetime] NOT NULL)
short description about the table, User can opt to save “Desc”[User info as per the user] as a seperate version each time. I would like to generate a version number for each subVersion being created. The parentId field holds the PK ID for which the subversion is being created.
For example, some records below.
boardID UserCode Desc Version ParentID CreatedOn ModifiedOn
1 12343jhgs blah blah 1 0 --- ---
2 12343jhgs blah blah 1 1 --- ---
3 12343jhgs blah blah 2 1 --- ---
4 73627ggjh lol lol ol 1 0 --- ---
Hope you are getting the idea, for each subversion created i would like to generate a Version number that increments.
An example based on your sample data. I have assumed that the version number of instances of
boardIdwith the sameParentIdis determined by order of insertion.EDIT – re-reading your description and comments I realised that the parent and first child having version 1 was intentional: