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 2000 Forums
 SQL Server Development (2000)
 Creating constraint

Author  Topic 

SqlStar
Posting Yak Master

121 Posts

Posted - 2003-03-15 : 00:39:01
Hi,

What is the diffrences/advantages between creating primary key and foreign keys using "Varchar" and "Int" datatype?

":-)IT Knowledge is power :-)"

bjornh
Yak Posting Veteran

87 Posts

Posted - 2003-03-15 : 08:26:51
When you use int types as an key, your index will be a lot smaller and searching them will take less.
I believe that's the main isue.

Bjorn

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-03-15 : 08:40:09
But if you then have to create another table for those keys so that they point to useful data, you can end up with a lot of extra disk I/O to read that table. For relatively small tables it's insignificant, but it grows rather quickly as the tables get larger. If the key is actual, real data and not just generated by the system, you can often avoid having to join tables together to get useful information from a query. Integer keys rarely allow for that.

The best way to know is to TEST BOTH types in YOUR environment. You can't just assume one method will work better than the other, other factors will determine which key types work better in your system.

Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2003-03-15 : 10:29:45
quote:

When you use int types as an key, your index will be a lot smaller and searching them will take less.
I believe that's the main isue.

Bjorn



I thought the question was about DRI, not indexes. Sure they are related, but as far as PK and FK constraints, the enforcement of data integrity will work the same.

We're here ... we like natural keys ... get used to it ...

Jay White
{0}
Go to Top of Page
   

- Advertisement -