I am running Oracle 11gR2 11.2.0.3. I have two tables:
table1
contains a column namedSUBJECT_ID
, whose datatype isNUMBER(7,0)
(numbers range from 13 to 48480)table2
contains a a column namedSUBJECT_ID
, whose datatype isNUMBER
, and is a foreign key totable1.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:
x1
will be 21 bytes whilex2
will be 2 bytes. By not specifying the data type, you're taking up extra space that may not be needed.