Moore
Moore

Reputation: 633

Create table with numeric column

CREATE TABLE SampleMath
(m  NUMERIC (10,3),
 n  INTEGER,
 p  INTEGER);

Question: why there is a space between NUMERIC and (10,3).

At first, I thought (10,3) is a column constraint. However, it doesn't seem to be correct as common constraints are NOT NULL, UNIQUE as listed here.

Then I thought that it could be the property (precision, scale) for the datatype NUMERIC as described in the documentation. In that case, I think there should not be a space between NUMERIC and (10,3). I also tried to delete the space in between and it seems the code still works. In my understanding, if it is the property, there should not be a space, which makes me really confused.

Any help to clarify this would be really appreciated. Thanks for your help in advance.

Upvotes: 1

Views: 24101

Answers (1)

GMB
GMB

Reputation: 222432

NUMERIC (10,3) is a datatype. It can store a number with a total of 10 digits (that's called precision), including 3 decimal (aka scale, ie the count of digits at the right of the decimal point). So basically the biggest number that it can store is 9999999.999.

The space between NUMERIC and the definition of its scale and precision is not meaningful. Even a new line would be OK, like:

CREATE TABLE SampleMath
(m  NUMERIC 
        (10,3),
 n  INTEGER,
 p  INTEGER);

Upvotes: 5

Related Questions