Friday, July 1, 2011

What's the best practice for primary keys in tables?

1. Primary keys should be as small as necessary. Prefer a numeric type because numeric types are stored in a much more compact format than character formats. This is because most primary keys will be foreign keys in another table as well as used in multiple indexes. The smaller your key, the smaller the index, the less pages in the cache you will use.
When dealing with "small" databases this stuff doesn't matter so much. But when you deal with large db's all of the little things matter. Just imagine if you have 1 billion rows with int or long pk's compared to using text or guid's. There's a huge difference!

Reference:
1 .http://stackoverflow.com/questions/337503/whats-the-best-practice-for-primary-keys-in-tables

No comments:

Post a Comment

Devops links

  Build Versioning in Azure DevOps Pipelines