Wednesday, March 7, 2012

Decimal in Design Table

Hi, this is a trivial question.
I am trying to make a 2 point decimal stored in the sql database.
For example,
a field called, "Points", will have values such as 100.00, 107.07, 99.88, 56.01 etc...
and all decimals like 108.009 would round up to 108.01.

Now, in the design table of the sql server.
Column Name Data Type Length Allow Nulls
Points Decimal 9 Yes
------------
Description (blank)
Default Value (blank)
Precision 18
Scale 0
Formula (blank)
The numbers in red are assign by default. How would I alter that to make it a 2 decimal point number?
What should I change to make it work?
Thank youyou can do it in the design view. or you can also do it from query analyzer with an ALTER TABLE stmt. From books on line:

C. Changing the data type of a column

The following example changes a column of a table fromINT toDECIMAL.

Copy Code
CREATE TABLE doc_exy ( column_a INT ) ;GOINSERT INTO doc_exy (column_a)VALUES (10) ;GOALTER TABLE doc_exy ALTER COLUMN column_a DECIMAL (5, 2) ;GODROP TABLE doc_exy ;GO

|||Thank you so much. It's always good to know how to do it in code. However, how do I do it in design view?
|||ChangeScaleto 2.
decimal[(p[,s])] andnumeric[(p[,s])]

Fixed precision and scale numbers. When maximum precision is used, valid values are from - 10^38 +1 through 10^38 - 1. The SQL-92 synonyms fordecimal aredec anddec(p,s).numeric is functionally equivalent todecimal.

p (precision)

The maximum total number of decimal digits that can 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, which is 38. The default precision is 18.

s(scale)

The maximum number of decimal digits that can be stored to the right of the decimal point. Scale must be a value from 0 throughp. Scale can be specified only if precision is specified. The default scale is 0; therefore, 0 <=s <=p. Maximum storage sizes vary, based on the precision.

|||Thanks. That's the exact information I was looking for.

No comments:

Post a Comment