Home » SQL & PL/SQL » SQL & PL/SQL » Why Primary Key is always selected as an Integer ?
Why Primary Key is always selected as an Integer ? [message #201645] Mon, 06 November 2006 03:27 Go to next message
frank.svs
Messages: 162
Registered: February 2006
Senior Member
Hi pals,

I have one doubt.

Why it is always recommeded to choose an integer column as Primary Key. Why not a varchar type.

Any Explaination Plz.

Thanks in advance.
franky
Re: Why Primary Key is always selected as an Integer ? [message #201654 is a reply to message #201645] Mon, 06 November 2006 03:53 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
In oracle, I suspect that it's because you can populate an Number column easily from a sequence.

In general, I guess it's because numbers have an intrinsic order.
Re: Why Primary Key is always selected as an Integer ? [message #202024 is a reply to message #201654] Tue, 07 November 2006 22:21 Go to previous messageGo to next message
frank.svs
Messages: 162
Registered: February 2006
Senior Member


Any More. I need some more inputs which shows evidence.

Thanks and Regards,
frank
Re: Why Primary Key is always selected as an Integer ? [message #202066 is a reply to message #202024] Wed, 08 November 2006 01:29 Go to previous messageGo to next message
rleishman
Messages: 3724
Registered: October 2005
Location: Melbourne, Australia
Senior Member
Numbers will generally take up less space.

One single byte can any one of store 256 different numeric keys, whereas it can store only 80 or so LEGIBLE character keys.

So, if you have a table with 1 Million different keys, the total space taken will be considerably less with a numeric key.

Ross Leishman
Re: Why Primary Key is always selected as an Integer ? [message #202097 is a reply to message #202066] Wed, 08 November 2006 03:26 Go to previous messageGo to next message
amul
Messages: 252
Registered: April 2001
Location: Chennai
Senior Member
and moreover a confusion arises when the text is in caps and small case..both will be accepted that might be a problem too
Re: Why Primary Key is always selected as an Integer ? [message #202105 is a reply to message #202097] Wed, 08 November 2006 03:57 Go to previous message
Admin@Lightsql.Com
Messages: 36
Registered: November 2006
Member

It depends. As JRowbottom pointed out easy to maintain by sequence.
Varchar2 has got case sensitive/insensitive issues.

By default, you can have primary with number, varchar2 or date etc, no restrictions.

However, many applications, such as oracle applications, siebel, peoplesoft...etc, handle the some form of id as their primary key in order to refer and integrate with the associated (application maintained - not database enforced) foreign keys. Hence, they find it easy to system generate the ids through sequence, and apply that ids to primary and foreign keys. These ids are not known to end users, but limited to applications development teams.

Jayg
Fun Programming with Oracle & Visual C++

[Updated on: Wed, 08 November 2006 04:05]

Report message to a moderator

Previous Topic: Sql Help
Next Topic: order and order_item trigger to send email
Goto Forum:
  


Current Time: Fri Dec 09 17:15:21 CST 2016

Total time taken to generate the page: 0.35385 seconds