Database primary key design description
In my release example, a WF-based business process platform,
N12345B
//
Almost all data structures use the Guid data type as the ID. Does this ID only serve as the serial number? This ID is not used for the relationship between all tables, and xxxNo is used.
//
Here, I will explain the reasons for using this Guid
Why do I add a Guid column to each table?
This is because I want to process concurrency, which is described as follows:
The Guid column is used to ensure that each record has a unique identifier in the fully-Open Database,
I usually maintain such a table in the memory as needed
Guid |
UserID |
State |
76C43F0D-F39E-458b-9E40-D4D70703FF2E |
001 |
|
76C43F0D-F39E-458b-9E40-D4D70703FF2E |
002 |
|
76C43F0D-F39E-458b-9E40-D4D70703FF2E |
003 |
|
When a user [001] queries a record, if the user selects the option [notify me immediately after modification by another user.
The server adds the Guid and UserID of the record queried by the user to the table above.
After a record is modified, the system will go to the table above to check whether the Guid of the record is registered. If it is registered, a notification will be sent to the corresponding UserID.
Of course, this is only an application of this Guid. I also use this Guid when doing concurrent modification arbitration. In this regard, I will write a special article to introduce it later.
Why do Guid columns have primary keys?
Despise your laziness first (^_^)
When using Linq To SQL, the table's primary key cannot be modified, so I use Guid as the primary key, and the Business primary key makes me a unique key.