Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12345»»»

Datatypes In Your Mind Expand / Collapse
Author
Message
Posted Monday, May 5, 2014 8:32 PM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: Moderators
Last Login: Wednesday, November 26, 2014 9:27 AM
Points: 6,800, Visits: 1,917
Comments posted to this topic are about the item Datatypes In Your Mind

Andy
SQLAndy - My Blog!
Connect with me on LinkedIn
Follow me on Twitter
Post #1567755
Posted Monday, May 5, 2014 9:44 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, November 26, 2014 7:40 AM
Points: 335, Visits: 238
The list shown here includes bit in the list of "exact numeric types".
http://msdn.microsoft.com/en-us/library/ms187752.aspx (Data Types (Transact-SQL))

The definition of bit, shown here, calls it "An integer data type that can take a value of 1, 0, or NULL."
http://msdn.microsoft.com/en-us/library/ms177603.aspx (bit (Transact-SQL))

Since:
- a bit can only store 0 and 1, so it is an "exact number integer data type", as specified in the question
- bit doesn't support negative numbers
- 0-1 is a smaller range than 0-255

The correct answer should be bit.
Post #1567766
Posted Monday, May 5, 2014 10:18 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 12:43 AM
Points: 2,421, Visits: 6,738
Good question, thanks!
Did think a bit for a second
Post #1567768
Posted Monday, May 5, 2014 10:58 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 8:55 PM
Points: 35,618, Visits: 32,214
Even though I strongly disagree that BIT is an integer datatype simply because it can't be used in certain bits of math, such as a SUM(), I have to agree with Stephen based soley on what the Microsoft documentation says... and it does say...

"An integer data type that can take a value of 1, 0, or NULL."



Anyone that answered "BIT" should get the point... if points matter to anyone.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1567771
Posted Monday, May 5, 2014 11:56 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 8:55 AM
Points: 13,570, Visits: 11,383
Misread the question and thought the data type was supposed to store negatives as well...
Need more caffeine.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1567782
Posted Tuesday, May 6, 2014 1:04 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 7:58 AM
Points: 2,600, Visits: 2,448
stephen.long 56048 (5/5/2014)
The list shown here includes bit in the list of "exact numeric types".
http://msdn.microsoft.com/en-us/library/ms187752.aspx (Data Types (Transact-SQL))

The definition of bit, shown here, calls it "An integer data type that can take a value of 1, 0, or NULL."
http://msdn.microsoft.com/en-us/library/ms177603.aspx (bit (Transact-SQL))

Since:
- a bit can only store 0 and 1, so it is an "exact number integer data type", as specified in the question
- bit doesn't support negative numbers
- 0-1 is a smaller range than 0-255

The correct answer should be bit.


The correct answer IS bit!

+1
Andy, are you hungry?
Post #1567803
Posted Tuesday, May 6, 2014 1:06 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, July 21, 2014 2:56 AM
Points: 2,603, Visits: 2,061
Good One, Thanks!

---------------------------------------------------
"Thare are only 10 types of people in the world:
Those who understand binary, and those who don't."
Post #1567805
Posted Tuesday, May 6, 2014 1:39 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Wednesday, November 26, 2014 11:46 PM
Points: 569, Visits: 903
Jeff Moden (5/5/2014)
Even though I strongly disagree that BIT is an integer datatype simply because it can't be used in certain bits of math, such as a SUM(), I have to agree with Stephen based soley on what the Microsoft documentation says... and it does say...

"An integer data type that can take a value of 1, 0, or NULL."



Anyone that answered "BIT" should get the point... if points matter to anyone.


Jeff, I think point matters and that is why we have point system for QoTD
Anyway Andy has not mentioned in his explanation that why bit is not correct answer as per the question


--rhythmk
------------------------------------------------------------------
To post your question use below link

http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1567813
Posted Tuesday, May 6, 2014 2:07 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 9:55 AM
Points: 1,038, Visits: 2,342
Good one Andy, understanding those variable/s from different angle.

hmm, according to the driver, it is tinyint, but the passenger (me) who answered, bit, does not agrees with the driver... and it leads to heated argument... driver loses is mind and lost control.. and we all know the rest what is going to happen... and... now I am scared of SQL.

-//edit; fixed the typo and added "(me)"


ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
Post #1567824
Posted Tuesday, May 6, 2014 2:34 AM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Monday, November 24, 2014 8:49 AM
Points: 662, Visits: 966
Thanks for the question,

I guess the author goes more this way

--the smallest exact number integer data type that can't support a negative number

declare @bit bit
set @bit = -1

Command(s) completed successfully.

declare @tinyint tinyint
set @tinyint = -1

Msg 220, Level 16, State 2, Line 5
Arithmetic overflow error for data type tinyint, value = -1.


so certainly bit datatype can get a negative value which will be transformed to 0 or 1.
Post #1567833
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse