SQL data types

  • Hi Experts,Please help what data type must i use for these numbers 
     Transaction code 2.011.126  and 
     Transaction amount 656.160.000

    when creating a table  in SQL.

    I am new to SQL.

    Many thanks

  • tmmutsetse - Thursday, October 4, 2018 9:05 AM

    Hi Experts,Please help what data type must i use for these numbers 
     Transaction code 2.011.126  and 
     Transaction amount 656.160.000

    when creating a table  in SQL.

    I am new to SQL.

    Many thanks

    Are those 2 decimal points?

    You've been posting questions for a while now on SSC, one would hope you know your datatypes now. You know your data far better that we ever will, and giving us one example for both columns won't give us enough detail to tell you, with confidence, what datatype you could use. We could tell you what is an appropriate datatype for that scalar value, but that isn't your question.

    At the end of the day, always store your data in a datatype that is appropriate for it. Store a date in the date datatype, a time in the time datatype. If it's a date and time then use datetime2(x), where x is a precision relevant to your data. If it's a number, you have several options as well, int, decimal and float. If you're only working with "whole numbers", then an int probably makes sense. If you're working with currency, then decimal makes more sense (in my opinion), however, there's valid arguments both for and against float and decimal; as they each have their own "flaws". If you're working with very large numbers, however, and precision isn't key, then float is the right choice.

    (n)varchar is not a "one size fits all" datatype. If you are storing dates, for example, in a varchar then you are storing it incorrectly. (In my opinion) you should be using a (n)varchar when your data doesn't fit a different datatype. For example, phone numbers don't fit in a numerical datatype as they contain leading 0's. They might also contain whitespace (for formatting) or are prefixed with a +, if the number is international. A monetary currency value, however, doesn't belong in a (n)varchar though because it is preceded/suffixed by a currency symbol. Regardless of the country, currency value is a numerical value and should be stored as such. If you need to store the currency type (GBP/£, USD/$, EUR/€, etc), then do so in a different column.

    Like I said, we can't tell you here what is appropriate, we don't have enough information. However, I would suggest that you are not as new to SQL as you are suggesting you are, certainly you should be familiar with the different datatypes of SQL Server and some of their limitation, and so you should know what is right for what you need.

    For reference, however, you can find all the current SQL Server datatypes in the documentation: https://docs.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql?view=sql-server-2017. Note that some of these are deprecated, like (n)text and image, and others are recommend over others (by Microsoft), such as datetime2, date, etc over datetime.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Thanks Tom for your time to answer me .I appreciate your sound advice.I will look at the link

Viewing 3 posts - 1 through 2 (of 2 total)

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