A username or any such unique field that holds meaningful data is subject to changes. A name may have been misspelled or you might want to edit a name to choose a better one, etc. etc.
Primary keys are used to identify records and, in conjunction with foreign keys, to connect records in different tables. They should never change. Therefore, it is better to use a meaningless int field as primary key.
By meaningless I mean that apart from being the primary key it has no meaning to the users.
An int identity column has other advantages over a text field as primary key.
- It is generated by the database engine and is guaranteed to be unique in multi-user scenarios.
- it is faster than a text column.
- Text can have leading spaces, hidden characters and other oddities.
- There are multiple kinds of text data types, multiple character sets and culture dependent behaviors resulting in text comparisons not always working as expected.
int primary keys generated in ascending order have a superior performance in conjunction with clustered primary keys (which is a SQL-Server specialty).
IDENTITYfor such columns (which minimizes index fragmentation) means it's often worthwhile to do this, even if you're going to be addingUNIQUEconstraints on the "real" keys anyway for consistency (since those separate indexes are easier to maintain than what is presumably the clustered index). There's also a big contingent of purists who think surrogate keys are the devil's toys, though. :P - Jeroen Mostertidentitycolumn, and sending those out into the real world (on invoice documents/emails/etc), then it's not a surrogate, it's part of the model. If the identity is "purely internal", it's merely an optimization. - allmhuran