Numeric Data Types

  • Orlando Colamatteo

    SSC Guru

    Points: 182269

    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

  • Mr. Kapsicum

    SSCertifiable

    Points: 6128

    Very Good Question.

    had to give a deep thought before answering. Thanks

  • This was removed by the editor as SPAM

  • pmadhavapeddi22

    SSCertifiable

    Points: 5306

    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

    )

  • paul.knibbs

    SSCoach

    Points: 15270

    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!

  • briankwartler

    Ten Centuries

    Points: 1332

    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.

  • Orlando Colamatteo

    SSC Guru

    Points: 182269

    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

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 720447

    The explanation has been corrected. Thanks

  • Orlando Colamatteo

    SSC Guru

    Points: 182269

    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

  • Rich Mechaber

    SSChampion

    Points: 10935

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

    Rich

  • mhynds

    SSC-Addicted

    Points: 452

    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?

  • ybais

    Newbie

    Points: 8

    Braintwister 🙂 Nice one.

  • Stephanie Giovannini

    SSCertifiable

    Points: 7422

    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

    )

  • enoch.evans

    Old Hand

    Points: 331

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

  • Orlando Colamatteo

    SSC Guru

    Points: 182269

    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 30 total)

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