What are the best practices for using a GUID as a primary key, specifically regarding performance?

前端 未结 7 1815
日久生厌
日久生厌 2020-11-22 09:22

I have an application that uses GUID as the Primary Key in almost all tables and I have read that there are issues about performance when using GUID as Primary Key. Honestly

7条回答
  •  -上瘾入骨i
    2020-11-22 10:06

    This link says it better than I could and helped in my decision making. I usually opt for an int as a primary key, unless I have a specific need not to and I also let SQL server auto-generate/maintain this field unless I have some specific reason not to. In reality, performance concerns need to be determined based on your specific app. There are many factors at play here including but not limited to expected db size, proper indexing, efficient querying, and more. Although people may disagree, I think in many scenarios you will not notice a difference with either option and you should choose what is more appropriate for your app and what allows you to develop easier, quicker, and more effectively (If you never complete the app what difference does the rest make :).

    https://web.archive.org/web/20120812080710/http://databases.aspfaq.com/database/what-should-i-choose-for-my-primary-key.html

    P.S. I'm not sure why you would use a Composite PK or what benefit you believe that would give you.

提交回复
热议问题