How does the Data Type of an SQL table's PK impact query performance?
Specifically, I am interested in:
What is the difference between string datatypes (e.g.
nvarchar(n)
,varchar(n)
) and numeric datatypes (int
,bigint
,uniqueidentifier
)?What is the difference between the different string data types?
How does the maximum length of a string data type affect performance? Is there a specific
varchar
ornvarchar
length at which the performance sharply declines?What is the difference between the different numeric data types?
How do these variations impact:
Equality comparison of Primary Keys?
Joins on Primary Keys ?
Updates by Primary Key ?
Complex value comparisons by Primary Key (e.g. with
LIKE
on avarchar
or<=
on anint
)?
If there is a significant disparity between the different options, then, What measures can be taken to optimize performance with the slower data types?
How does a composite PK compare to the other options?
Update: To be clear, I understand this is a long question and I am not asking to be spoon-fed all this information. An answer that provides links to reliable online resources where I can find this information is completely sufficient.
Update 2:
I am using SQL Server Express 2008.