Wrox Programmer Forums Length vs precision in decimal datatype
 |
 SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
 Welcome to the p2p.wrox.com Forums. You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com

January 5th, 2004, 12:11 PM
 rvw Registered User Join Date: Oct 2003 Posts: 7 Thanks: 0 Thanked 0 Times in 0 Posts
Length vs precision in decimal datatype

If I create a column with the decimal datatype, the default length is 9. The precision is set to 18 and the scale to 0. What does this mean? Is the number of bytes used by the database 9 or 18? I suppose the 0 refers to the number of characters allowed behind the comma?

January 5th, 2004, 12:29 PM
 joefawcett Wrox Author Join Date: Jun 2003 Posts: 3,074 Thanks: 1 Thanked 38 Times in 37 Posts

Precision is how many digits in total, scale is how many after decimal point/comma. Length is how many bytes of memory it occupies.

--

Joe

January 5th, 2004, 12:36 PM
 Jeff Mason Friend of Wrox Join Date: Jun 2003 Posts: 839 Thanks: 0 Thanked 1 Time in 1 Post

The precision of a decimal (or numeric) datatype is the total number of digits (both to the left and right of the decimal point) which can be stored/represented. The scale is the number of digits to the right of the decimal point. The number of bytes of storage required depends on the precision. This table gives the storage in bytes for a given range of precision values:
Code:
```Precision  Bytes

1 - 9         5
10-19         9
20-28        13
29-38        17```

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com

 Similar Threads Thread Thread Starter Forum Replies Last Post possible loss of precision hobby Java Basics 7 September 19th, 2008 09:41 PM decimal data type all 0's after decimal gobotsoup SQL Server ASP 1 February 28th, 2007 02:32 PM Stored procedure decimal precision filipczako SQL Language 11 December 7th, 2005 04:21 PM Float precision nulogix C++ Programming 1 November 10th, 2005 09:53 PM How to control the decimal point precision johnsonlim026 ASP.NET 1.0 and 1.1 Basics 0 August 7th, 2005 11:58 PM