Reputation: 109
I know this has been discussed a lot, and my final choice is: I will use string as primary key, mainly for two reasons:
Is there anything I can do to improve performance, like creating a index?
I'm using Entity Framework code-first.
Upvotes: 0
Views: 550
Reputation: 835
Creating an index is unnecessary, as the PRIMARY KEY
provides a UNIQUE
, CLUSTERED
index.
Also note, most RDBMS have can more efficiently index fixed-length fields, such as CHAR
, vs. variable length fields like VARCHAR
.
One other possibility to consider:
An integer (INT
) primary key, with a unique index on the string value that you were originally going to use as the PRIMARY KEY
. This provides the ease of JOIN
ing on an integer field (not to mention space savings), while enforcing your original requirement.
Upvotes: 4
Reputation: 4860
Reduce the length of the VARCHAR
as much as possible.
Indexes are automatically created for PRIMARY KEYS
, so you don't have to create any index for this column.
Upvotes: 1