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
 General SQL Server Forums
 New to SQL Server Programming
 primary key data type

Author  Topic 

amalshah71
Starting Member

9 Posts

Posted - 2006-12-11 : 21:13:24
i have a employee table with various columns....
here i have emp_code as my primary key

now my concern is which data type is to be associated with the primary key(emp_code)

emp_code int not null,
OR
emp_code varchar not null,

wht i understand is to go for the simpler one....i.e. int, since it would be easy to deal with int data

now my basic question here is while creating tables which data type is to be assigned to emp_code (int or varchar) and on wht basis.......since both is possible...

help appreciated

cheers

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2006-12-11 : 21:32:18
If you are going to use numbers for the Emp_Code, why wouldn't you use INT? INT takes 4 bytes to store numbers from about minus two billion to about plus two billion. That's 4 bytes to store the equivelent of 10 characters max. VARCHAR takes 1 byte per character plus two bytes to hold the length. Since the length is dynamically allocated, it will always be slower than INT which has a fixed length. And, you can't make a VARCHAR column auto-numbering like you can INT.

--Jeff Moden
Go to Top of Page
   

- Advertisement -