Numeric Data Types

  • Comments posted to this topic are about the item Numeric Data Types

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Very Good Question.

    had to give a deep thought before answering. Thanks

  • This was removed by the editor as SPAM

  • I have created a test table with 9 columns covering all the given data types, then found the answer is 5. Thanks for the question

    create table test_tbl

    (

    col_1 DECIMAL(12,0),

    col_2 REAL,

    col_3 DOUBLE PRECISION,

    col_4 NUMERIC(5,4),

    col_5 INTEGER,

    col_6 FLOAT,

    col_7 NUMERIC(12,0),

    col_8 FLOAT(10),

    col_9 INT

    )

  • Didn't know that FLOAT(10) and FLOAT(24) (e.g. REAL) were equivalent, and had never heard of DOUBLE PRECISION, so ended up with the wrong answer. Still, good question, gave me something to think about!

  • I have a question about the answer provided. It says:

    Declaring a "FLOAT" without providing the number of bits to use, e.g. FLOAT(n), results in the default FLOAT(54) which is equivalent to DOUBLE PRECISION, a syntax feature carried forward from SQL Server's Sybase-roots that is not often documented.

    Shouldn't it say:

    Declaring a "FLOAT" without providing the number of bits to use, e.g. FLOAT(n), results in the default FLOAT(53) which is equivalent to DOUBLE PRECISION, a syntax feature carried forward from SQL Server's Sybase-roots that is not often documented.

  • briankwartler (5/5/2015)


    I have a question about the answer provided. It says:

    Declaring a "FLOAT" without providing the number of bits to use, e.g. FLOAT(n), results in the default FLOAT(54) which is equivalent to DOUBLE PRECISION, a syntax feature carried forward from SQL Server's Sybase-roots that is not often documented.

    Shouldn't it say:

    Declaring a "FLOAT" without providing the number of bits to use, e.g. FLOAT(n), results in the default FLOAT(53) which is equivalent to DOUBLE PRECISION, a syntax feature carried forward from SQL Server's Sybase-roots that is not often documented.

    Good catch. There is a typo in my explanation. I will email Steve to see if it can be corrected.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • The explanation has been corrected. Thanks

  • Steve Jones - SSC Editor (5/5/2015)


    The explanation has been corrected. Thanks

    Thanks Steve.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • So close. I replied 6. Missed REAL = FLOAT(10) = FLOAT(24).

    Rich

  • While I got the answer correct, it was based on the number of choices. However the question asks "how many distinct data types are represented in this list?" Coming from an old-school Fortran approach, Float, double precision, real are not really different data types they are variations on a single theme. The same could be said for decimal (12, 0) and numeric. I would submit that the list contains only three really distinct data types. Discussion?

  • Braintwister 🙂 Nice one.

  • While decimal and numeric are functionally equivalent, they are not the same type. There are six types in the question.

    The system_type_id for decimal and numeric is not the same. The other type synonyms (such as REAL and FLOAT(10)) result in the same system_type_id, max_length, precision and scale.

    CREATE TABLE #test (

    dec_12 DECIMAL (12,0),

    num_12 NUMERIC (12,0),

    int1 INTEGER,

    int2 INT,

    real0 REAL,

    float_10 FLOAT(10),

    float0 FLOAT,

    double_precision DOUBLE PRECISION,

    num_5_4 NUMERIC(5,4));

    SELECT name, system_type_id, max_length, precision, scale

    FROM tempdb.sys.columns

    WHERE OBJECT_ID = OBJECT_ID('tempdb..#test');

    SELECT COUNT(*) correct_answer_to_question

    FROM (

    SELECT DISTINCT system_type_id, max_length, precision, scale

    FROM tempdb.sys.columns

    WHERE OBJECT_ID = OBJECT_ID('tempdb..#test')) a;

    If you create this table (but not in tempdb) and script the table creation, the output looks like this:

    CREATE TABLE [dbo].[test](

    [dec_12] [decimal](12, 0) NULL,

    [num_12] [numeric](12, 0) NULL,

    [int1] [int] NULL,

    [int2] [int] NULL,

    [real0] [real] NULL,

    [float_10] [real] NULL,

    [float0] [float] NULL,

    [double_precision] [float] NULL,

    [num_5_4] [numeric](5, 4) NULL

    )

  • Per https://msdn.microsoft.com/en-us/library/ms173773.aspx real is equivalent to float(24) not float(10).

  • enoch.evans (5/5/2015)


    Per https://msdn.microsoft.com/en-us/library/ms173773.aspx real is equivalent to float(24) not float(10).

    From the article:

    SQL Server treats n as one of two possible values. If 1<=n<=24, n is treated as 24. If 25<=n<=53, n is treated as 53.

    float(1-23) = float(24) = real

    float(25-53) = float

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 15 posts - 1 through 15 (of 29 total)

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