56

I found a table with this a column from this data type

numeric(18, 0)

what is that please? and why does 0 and 18 mean

I already check this question Difference between numeric, float and decimal in SQL Server but couldn't understand it.\

can I add (-10) in that column?

can I add all negative number in that column?

can I add any positive number in that column?

Update 1

This is a sample of the data I found in that column

100
263
13
2
9
4
3
3
28
15
33
16
135
50
64
60
100
500
150

Update 2 Is it possible to have - and + ?

8
  • 1
    It is essentially a REALLY big int. Yes you have a negative number. No you can't have any number, it must be no larger than 18 significant digits. Commented Aug 7, 2014 at 19:49
  • 1
    Here is a link to BOL datatypes. msdn.microsoft.com/en-us/library/ms187752.aspx Commented Aug 7, 2014 at 19:50
  • @SeanLange you said that it must be no larger than 18 significant digits but please check the updated question, there are values less that 18 digits Commented Aug 7, 2014 at 19:51
  • @SeanLange that link didn't provide information, are you sure of it please? Commented Aug 7, 2014 at 19:53
  • 5
    Someone really loves to waste space if that sample is representative of the data Commented Aug 7, 2014 at 19:54

2 Answers 2

89

The first value is the precision and the second is the scale, so 18,0 is essentially 18 digits with 0 digits after the decimal place. If you had 18,2 for example, you would have 18 digits, two of which would come after the decimal...

example of 18,2: 1234567890123456.12

There is no functional difference between numeric and decimal, other that the name and I think I recall that numeric came first, as in an earlier version.

And to answer, "can I add (-10) in that column?" - Yes, you can.

Sign up to request clarification or add additional context in comments.

3 Comments

@AgnieszkaPolec yes you can have negative values. You need to learn about BOL (books online). It is the documentation for sql server. I posted a link the datatypes page earlier. The links from there will take you to the datatype pages for each datatype. It explains them in great detail.
@SeanLange thanks but I checked that link and browsed to numeric section, it was empty of description. it just has links to decimal and float. Anyway, now I understood the concept of numeric.
Maybe you looked at the wrong page or something because the numeric page is pretty in depth. decimal [ (p[ ,s] )] and numeric[ (p[ ,s] )] Fixed precision and scale numbers. When maximum precision is used, valid values are from - 10^38 +1 through 10^38 - 1. The ISO synonyms for decimal are dec and dec(p, s). numeric is functionally equivalent to decimal. p (precision) The maximum total number of decimal digits that will be stored, both to the left and to the right of the decimal point. The precision must be a value from 1 through the maximum precision of 38....too long to fit here.
22

This page explains it pretty well.

As a numeric the allowable range that can be stored in that field is -10^38 +1 to 10^38 - 1.

The first number in parentheses is the total number of digits that will be stored. Counting both sides of the decimal. In this case 18. So you could have a number with 18 digits before the decimal 18 digits after the decimal or some combination in between.

The second number in parentheses is the total number of digits to be stored after the decimal. Since in this case the number is 0 that basically means only integers can be stored in this field.

So the range that can be stored in this particular field is -(10^18 - 1) to (10^18 - 1)

Or -999999999999999999 to 999999999999999999 Integers only

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.