![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Should I define these primary keys as char[5] or varchar[5]? |
#3
| |||
| |||
|
|
I'm planning the structure of a SqlServer 2005 database for a new application. The requirement is that primary keys must be "natural"; i.e. in the table Customers the primary key will be a max. 10 characters string (but the string may be filled i.e. with only 5 charachters). Should I define these primary keys as char[5] or varchar[5]? I'm interested in your opinion in particular about performace issue, because there will be tables with millions of records... |
#4
| |||
| |||
|
|
Hi, I'm planning the structure of a SqlServer 2005 database for a new application. The requirement is that primary keys must be "natural"; i.e. in the table Customers the primary key will be a max. 10 characters string (but the string may be filled i.e. with only 5 charachters). Should I define these primary keys as char[5] or varchar[5]? I'm interested in your opinion in particular about performace issue, because there will be tables with millions of records... Thanks, Davide. |
#5
| |||
| |||
|
|
What sort of strings do you expect? If the values will be digits and upper- case characters, you way want to consider a binary collation for the column, at least if your default collation is a Windows collation. |
#6
| |||
| |||
|
|
Because of some other considerations (the 'first' VARCHAR column will cost an additional 5 bytes per row), when in doubt, I would choose CHAR over VARCHAR. In your case, I would choose VARCHAR(10) if the average length is 6 or smaller. Otherwise I would choose CHAR(10). |
#7
| |||
| |||
|
|
How do I set binary collation on a single column? |
|
Do you think that this will improve performance on lookups? |
|
Do you think that having a single column with a different collation will not decrease performance? |
#8
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |