SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Numeric Datatype Decisions

By Brian Knight, 2001/05/17

Total article views: 12930 | Views in the last 30 days: 72
Last week we discussed character datatypes and their performance effects on your database. This week,we will dive into numeric datatypes. We will discuss how SQL Server numeric datatypes are stored and the pros and cons of each.

The first category we will discuss are exact numeric datatypes. This group gets its name from its ability to set the precision and scale. Precision is the total amount of digits to the right and left of the decimal where scale is how many places to the right of the decimal SQL Server will store. SQL Server uses rounding to estimate any decimal spots past the scale. There are two types of exact datatypes:

  • Decimal - can store values between -1038 and 1038. Uses between 2 and 17 bytes depending on the precision.
  • Numeric - can store values between -1038 and 1038. Uses between 2 and 17 bytes depending on the precision.

You may notice that the decimal and numeric datatype are exactly the same. Numeric is kept in SQL Server mostly for backward capatability. You may want to consider stopping the use of numeric datatypes so you are prepared when the datatype is retired.

The next category is absolute or fixed numeric datatypes. These datatypes can not be adjusted using a precision. There are three types of fixed datatypes:

  • Int - Can stored between -2,147,483,648 to 2,147,483,647. Uses 4 bytes of storage.
  • SmallInt - Can store between -32,768 to 32,767. Uses 2 bytes of storage.
  • TinyInt - Can store values between 0 and 255. Uses 1 bytes of storage.
Since Intel processors use 4 byte chunks of data to work with at a time, the int datatype will run most optimal.

You also have more specialized datatypes like money and small money. Money can store between -$922,337,203,685,477.5808 to $922,337,203,685,477.5807 and uses 8 bytes of storage. Small money on the otherhand stores between -$214,748.3648 to $214,748.3647 and uses 4 bytes of storage. Both of these datatypes stores a the value 20.5 as $20.5. As a general rule, use exact datatypes to represent these values and perform the data manipulation at the application level.

By Brian Knight, 2001/05/17

Total article views: 12930 | Views in the last 30 days: 72
Your response
 
 
Related tags

Data Types    
Database Design    
 
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com