Editorials

Hidden Rounding

SSWUGtv
With Stephen Wynkoop
In today’s episode: keeping the end in mind: Laura Rose teaches you how to take stock of your business and make good goals.
Watch the Show

Hidden Rounding
Many versions of SQL support a Decimal data type. Microsoft SQL Server, in particular, allows the user to specify the total number of digits as well as the number of decimal places a particular variable or column supports.

The ability to define the number of decimals and decimal places is valuable because you can optimize the amount of space required by narrowing the data type to only the precision you require.

This is where hidden rounding comes into place. When working with an MS SQL Server data type such as Money, or Small Money, you know what the precision is based on the specific data type. In contrast, when you work with a decimal data type, you have to look at the metadata of the table or definition of a variable in order to know the true precision of the data contained.

Because of implicit conversion, when mixing different decimal data types, some operations round the more precise variable implicitly to the lower precision definition. Without an understanding of the precision of all data types involved, rounding may be implicitly happening, and not apparent to the programmer.

The rounding may not be a bad, or undesirable thing. However, if it is not apparent that rounding is occurring, there can be unexpected consequences.

How do you use Decimal data types in your SQL Schemas? Do you prefer to use other data types? If you do use decimals, do you have best practices you have found useful? Share your thoughts with us by sending your Email to btaylor@sswug.org.

Cheers,

Ben

$$SWYNK$$

Featured Article(s)
UNIX for DBAs (Part 1)
UNIX is one of the most popular operating system for running database management systems. Of course, Windows is popular, too, as are z/OS and even OS/400, not to mention Linux (but that is a variant of UNIX). At any rate, UNIX is ubiquitous in the realm of database processing and it is important that DBAs know the basics of UNIX in order to effectively manage the databases on that platform. This article offers up a short tutorial on the basic UNIX operating system commands and features that are most important for DBAs to understand.

Featured White Paper(s)
All-At-Once Operations
Written by Itzik Ben-Gan with SolidQ

SQL supports a concept called all-at-onc… (read more)