Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NUMERIC Scale & Precision required in future versions?

Status
Not open for further replies.

TallOne

Programmer
May 14, 2004
164
US
Although I haven’t been able to find the MS documentation, I read that in future versions of SQL Server, scale and precision will be required for data type NUMERIC. Has anyone read or heard about this?
 
Haven't heard of it, but I've never created a column without it. If I don't want any decimal places, I'll use one of the integer types.
 
Technically you are required to have a valid scale,precision. You get around entering it by the defaults.

Although I have yet to read of removal of the default values I wish they would to promote better design and coding methods

Same rules apply to things like not stating length in varchar etc..

 
In my experience, developers often use NUMERIC as a replacement for Int. The default precision and scale for Numeric is 18,0. Notice the 0. This does not allow for fractional values.

This would allow for values ranging from -999,999,999,999,999,999 to 999,999,999,999,999,999

It takes 9 bytes to store a Numeric(18,0) but only 4 bytes to store an int. Of course, Numeric(18,0) can store a larger number than an int, but you can easily use a big int too.

Code:
Declare @Blah Numeric
Set @Blah = 1

SELECT SQL_VARIANT_PROPERTY(@Blah, 'BaseType') AS [Base Type], 
       SQL_VARIANT_PROPERTY(@Blah, 'Precision') AS [PRECISION],
       SQL_VARIANT_PROPERTY(@Blah, 'Scale') AS [Scale],
       SQL_VARIANT_PROPERTY(@Blah, 'TotalBytes') As TotalBytes


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thanks for the responses. At some point in my career I picked up the habit of using
DECLARE @MyVAR AS NUMERIC(18,0)
my supervisor asked me to start using
DECLARE @MyVAR NUMERIC
unless I knew something that he didn't. I told him that I had heard it would be required in future versions as well as possibly use more memory. So here I am looking to see if anyone else had heard about it...

Thanks
 
Your supervisor isn't the best lead. Best advice you can get at this point is don't pick up bad habits from peers. Even if they are in higher positions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top