Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Primary Key of type string ?

Re: Primary Key of type string ?

From: sybrandb <sybrandb_at_gmail.com>
Date: 31 May 2007 02:26:46 -0700
Message-ID: <1180603606.504601.317700@o5g2000hsb.googlegroups.com>


On May 31, 11:03 am, "Oriane" <ori..._at_guermantes.fr> wrote:
> Hi there,
>
> Just a basic question from a beginner in Oracle. Is is the "standard choice"
> to use a column of type "int" for the primary key ? I suppose that this is a
> performance issue ? What about choosing a type "string/char" for a primary
> key ?
>
> Sincerely
>
> Oriane

The standard choice is a number(10). Int is a non-existing datatype in Oracle and will be automagically translated to number(39). Numbers are stored packed, two digits in a byte. Choosing string/char is a bad idea.
First of all, it will take more space, but secondly string comparisons are internally more expensive: the string will be compared until the first pair of characters that is different. Do *NOT* store numbers padded with zeroes in a string! This will result in much more I/O and all of your code is sensitive to implicit type conversion, and Oracle will always convert the database column to the variable, thus suppressing index usage.

--
Sybrand Bakker
Senior Oracle DBA
Received on Thu May 31 2007 - 04:26:46 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US