There is a table in SQL Server. The design is as follows:
Instance No. pi_sequence
Root instance id pi_rootid
Parent instance id pi_fatherid
The instance serial number column is the identity column. Both the root instance id and parent instance id reference the instance serial number column. Three records with identical fields may appear, the previous practice was to use two statements: Insert first and then update the root instance id and parent instance id. For details, see how to get the newly inserted identity column value in C #. today, I tried the following statement at will: insert into tbprocessinstance (process_id, pi_rootid, pi_fatherid) values (1, scope_identity () + 1, scope_identity () + 1)
It can be implemented in one step, but I do not know how the pi_rootid and pi_fatherid inserted in this statement in the transaction environment are null.
This problem is still caused by insufficient basic skills and insufficient understanding of the identity column. Otherwise, you will be able to operate it freely.