SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Datatypes In Your Mind


Datatypes In Your Mind

Author
Message
Andy Warren
Andy Warren
SSC-Dedicated
SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)

Group: Moderators
Points: 37148 Visits: 2762
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
stephen.long.1
stephen.long.1
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1200 Visits: 621
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.
Eirikur Eiriksson
Eirikur Eiriksson
SSC Guru
SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)

Group: General Forum Members
Points: 63193 Visits: 19803
Good question, thanks!
Did think a bit for a second:-D
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (339K reputation)SSC Guru (339K reputation)SSC Guru (339K reputation)SSC Guru (339K reputation)SSC Guru (339K reputation)SSC Guru (339K reputation)SSC Guru (339K reputation)SSC Guru (339K reputation)

Group: General Forum Members
Points: 339006 Visits: 42612
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)

Group: General Forum Members
Points: 99591 Visits: 13321
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?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Carlo Romagnano
Carlo Romagnano
SSCrazy Eights
SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)

Group: General Forum Members
Points: 9351 Visits: 3440
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?
free_mascot
free_mascot
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10993 Visits: 2250
Good One, Thanks!

---------------------------------------------------
"Thare are only 10 types of people in the world:
Those who understand binary, and those who don't."
rhythmk
rhythmk
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2648 Visits: 1125
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/
:-)
Raghavendra Mudugal
Raghavendra Mudugal
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4338 Visits: 2958
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... w00t 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.
sqldoubleg
sqldoubleg
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1713 Visits: 1363
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search