Data types

  • Is there any advantage to using char(1) vs smallint in terms of data analysis? Or in query speed? I have some fields that could go either way, and the char(1) would require less conversion of integer data to text on the frontend. I understood that SQL prefers integer data when possible for speed of analysis. Are there general guidelines for this?

    Thanks!!

    SMK

  • A couple of things to consider when making the decision:

    1. Validation: INT can ONLY be a number. CHAR can be a letter, number or symbol.

    2. Addition or concatenation: try this:

    DECLARE @num1 INT

    DECLARE @num2 INT

    DECLARE @num3 CHAR(1)

    DECLARE @num4 CHAR(1)

    SET @num1 = 1

    SET @num2 = 2

    SET @num3 = '1'

    SET @num4 = '2'

    SELECT @num1 + @num2

    SELECT @num3 + @num4

    The results will be 3 from the first select and 12 from the second select. The INTegers are added, but the CHARacters are concatenated.

    -SQLBill

  • Hmmmm, interesting.

    So if I have something like "right" and "left" that I want to designate as R or L instead of 1 and 2, there is no reason not to do it that way in terms of analysis. It would seem that in many cases, then, strings would be better since they convey some information rather than arbitrary number.

    Thanks,

    SMK

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

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