May 4, 2015 at 11:54 pm
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
May 5, 2015 at 12:16 am
Very Good Question.
had to give a deep thought before answering. Thanks
May 5, 2015 at 2:35 am
This was removed by the editor as SPAM
May 5, 2015 at 3:26 am
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
)
May 5, 2015 at 3:34 am
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!
May 5, 2015 at 4:44 am
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.
May 5, 2015 at 5:39 am
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
May 5, 2015 at 7:19 am
The explanation has been corrected. Thanks
May 5, 2015 at 7:44 am
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
May 5, 2015 at 8:02 am
So close. I replied 6. Missed REAL = FLOAT(10) = FLOAT(24).
Rich
May 5, 2015 at 8:18 am
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?
May 5, 2015 at 8:55 am
Braintwister 🙂 Nice one.
May 5, 2015 at 9:21 am
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
)
May 5, 2015 at 9:40 am
Per https://msdn.microsoft.com/en-us/library/ms173773.aspx real is equivalent to float(24) not float(10).
May 5, 2015 at 5:37 pm
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