Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 String v/s Integer as primary key

Author  Topic 

Dinky
Starting Member

37 Posts

Posted - 2008-02-12 : 10:12:36
Design/Modeling Question: How bad/different can 2-3 tables join be with a string field (individual) as primary key versus having additional integer field (individual) as primary key. This table can have upto 100000 records.

Please advice.

CShaw
Yak Posting Veteran

65 Posts

Posted - 2008-02-12 : 10:29:26
A join is going to work much better on an int then a string. How bad? You would have to run some tests to get some specific numbers.

Chris Shaw
www.SQLonCall.com
Go to Top of Page

Dinky
Starting Member

37 Posts

Posted - 2008-02-12 : 10:34:17
I though so that there will be lot of difference. I ran a test but String primary key worked actually better - that prompted me to post the topic here. Since both string and integer primary key will be managed by index which makes (?) the queries/joins behave same in both cases.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-12 : 11:02:34
It much depends on how long the string is.
A page can hold approx 8000 bytes (with 100% fill factor), which is about 2000 records per page to seek or scan later.
If your string is 8 bytes, every page can only hold 1000 records which essentially makes the index twice the size.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -