Proper Data Type

  • hi every one,

    I am new in database programming with sqlserver 2000. I am confused to handle data types wisely in sqlserver2000.For instance

    decimal: Fixed precision and scale numeric data from -10^38 +1 through 10^38 -1

    numeric: Fixed precision and scale numeric data from -10^38 +1 through 10^38 -1

    float: Floating precision number data from -1.79E + 308 through 1.79E + 308

    real: Floating precision number data from -3.40E + 38 through 3.40E + 38

    If the precision of decimal and numeric, are same then what is the necessity of having same data type in different name OR there exists some reasons behind that.

    and If i always use float data type insteed of real with small scale is there any problem here?

    Can you help me on that?



    ..Better Than Before...

  • For smaller scale values, I'm not sure it matters which you choose. I use numeric most of the time.

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

    The Best of SQL Server Central.com 2002 - http://www.sqlservercentral.com/bestof/

    http://www.dkranch.net

  • The only reason I can imagine why you should use float or real is when you deal with very large numbers like in astronomy.

    Frank

    http://www.insidesql.de

    http://www.familienzirkus.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Numeric(9,2) only uses 5 bytes, gives you two places past the decimal, say for cents. Good choice for storing bank account or credit card balances; or call center (time) statistics. I also store SMALLdatetime to save space, instead of datetime.

    Jules

    [font="Courier New"]ZenDada[/font]

  • AFAIK, all banking calculations are done with at least five decimal places.

    There are strict rules on how to do calculations, roundings, storing...

    In case of uncertainty I would always look this rules up whether you must comply with them.

    Frank

    http://www.insidesql.de

    http://www.familienzirkus.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Good point, Frank! I only need enough accuracy to report on call center stats, so I don't need the accuracy of a larger data type in my report level tables. Your business requirements should dictate the data types that you choose!

    Jules

    [font="Courier New"]ZenDada[/font]

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply