Ny point in specifying the precision and scale of a number for a foreign key

data integritydatatypesforeign keyoracle

I am running Oracle 11gR2 11.2.0.3. I have two tables:

  • table1 contains a column named SUBJECT_ID, whose datatype is NUMBER(7,0) (numbers range from 13 to 48480)
  • table2 contains a a column named SUBJECT_ID, whose datatype is NUMBER, and is a foreign key to table1.SUBJECT_ID.

Is there any point in specifying the precision and scale of table1.SUBJECT_ID (i.e. declaring it NUMBER(7,0) instead of simply NUMBER)?

The Oracle documentation advises to specify the precision and scale, as "it provides extra integrity checking on input". But in my case wouldn't the foreign key constraint take care of this integrity checking?

Best Answer

Connor MacDonald blogged about this over in NUMBER data type... what harm can it do? as well as Ask Tom: "How do I determine how much storage will be required for NUMBER(p, s)?". In short, it does matter.

Take this table:

CREATE TABLE T ( 
    x1 number,
    x2 number(6,3)
);

x1 will be 21 bytes while x2 will be 2 bytes. By not specifying the data type, you're taking up extra space that may not be needed.