Reputation: 3745
Which out of the INTEGER and VARCHAR datatypes is better for use as primary keys and why? I am used to making my primary keys INTEGER, will using VARCAHRs have a performance penalty?
Upvotes: 5
Views: 8328
Reputation: 1386
INT is faster for clustor index and if we want to join with other table.
You will get idea if you have understanding of Clustor Index and JOIN
Upvotes: 5
Reputation: 11
It depends on your business need. primary key is also a column, so the type really depends on the column. For example, consider a "student" table. student_id is the primary key. If you use integer to represent the id, the primary column should be defined as INT. Or if you use something like "G12345" (G indicates graduate student), then you should use varchar.
Upvotes: 1
Reputation: 17608
Integers:
Varchar:
Speed-wise, they're almost identical.
Upvotes: 3