Simple question. I have several different models stored in SQL databases. A Table of images records with byte data, large multi-field user data table, ect. All of these models require primary keys. Most beginner tutorials show usage of int for ids. Is this standard and professional. I find it odd to start use int since is variable in length and starts with 1 :S
Sorry for the amateur question, but I couldn’t find any adequate materials on the subject via google.
There’s nothing implicitly unprofessional about the use of
INTor any other integral data type as a primary key or identity column. It just depends on your business needs. In the interest of keeping programming as simple as possible, theINTdata type is a fine choice for many business needs:SELECTs andUPDATEs.BIGINTcan address more records than you can put in your database. Seriously.One reason you might not want to use an integral primary key:
Guid(orUNIQUEIDENTIFIERin SQL Server terms) for global uniqueness. In other words, if you migrate your data to another location, the primary key should still be unique.