Primary keys - root, serial or GUID keys?

When reading this and this , and then reading this (which refers to the other two, ironically), I wonder how big is the discussion on this topic? I'm a SQL Server guy, so I tend to use an identifier that is automatically generated in int form. However, when I know that I will need some form of replication between the server and the server or synchronization between the client and the server, I use the GUID as my key.

Question: Should I just use the GUID as the primary key in all tables at all times, just in case I need this possible scalability in the future? Does this make my scheme more flexible in that it can be transferred between platforms at all times? Does it help me maintain the flexibility of my ORM (regardless of taste) without embedding specific platform features?

Answers:

@David Archer: for your comment, I updated the post not to say "Natural Key". You are right that a natural key is defined as such . Thanks for the correction.

+3
source share
6

, , lo/hi, NHibernate ( ). GUID . , , .

, , , , , , . - " " NHibernate. UoW , , , .

GUID , GUID . " ", , DateInserted .

GUID , 4- , , .

- .:)

+4

, GUID . . SQL Server , " ", . . - ...

(, " " ). 40% , , .

+3

GUIDS , , (.. ..).

SQL Server , , .

, . 10 000 ( ), , , , 10 000 ( ), , ( ) Big Ints ( ) + (autonumber), .

- (, ).

+2

, , GUID SQL Server - , , .

- - GUID , .

- , , - GUID . , , , (, , ) .

, , , GUID (16 ) INT (4 ) - .

/ GUID, , - , SQL Server, - !

: , , , , . GUID ( ). GUID, NEWSEQUENTIALGUID() SQL Server, , .

+2

, " " , - . , GUID , , - .

+1

, GUID . 4 36 .

GUID , . URL , 1156712. - SO (, SU), , URL-, , , google. , GUID, int bigint, .

- . , " " .

+1

Source: https://habr.com/ru/post/1713112/


All Articles