Database – Using auto-increment clustered key and guid primary key together

databasedatabase-designprogramming practicessql server

My boss is the db administrator in a new software project and he came up with that design where every table will have both a auto-increment clustered key and a guid primary key (or possibly composite guid keys on some rare cases). Every relations between tables will still use pk as references, making the clustered field never used in views, procedures, functions or any code at all.

I'm no db guru, but I wonder if in this scenario it's even worth having a clustered index at all? I mean, won't records systematically be added to the end of tables? If so then why would I need this field?

Best Answer

Advantage:

  1. GUID is unique so in the long run if you run into this scenario where you can join using just Guid rather than PK+other field. ex:there sales, order, adjustment, and there is stock, instead of join using PK and transaction type, you can just join using Guid since it 99.9...% guaranteed unique.

  2. By using GUID you can generate GUID from code so it remove a need to do callback to get new PK.

  3. By having auto-increment you can get latest transaction just by ordering auto-increment instead of transaction date(stackoverflow using this method)

Related Topic