469,281 Members | 2,489 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,281 developers. It's quick & easy.

Data Type

I am a SQL newbie! What is the correct datatype to use, if I want to record
a checkbox from a web form? Thanks,
Darren
Jul 20 '05 #1
3 9263
Scrappy (ce*****@lan-specialist.com) writes:
I am a SQL newbie! What is the correct datatype to use, if I want to
record a checkbox from a web form? Thanks,


The most natural type to use would be bit, which only can hold the values 0
or 1.

If you want to stick to standards, you may avoid this datatype since it
is propritary to SQL Server and Sybase (or at least so claims Joe Celko).
In such case a char(1) column with the values T/F ot Y/N could be an
alternative. Or a tinyint column with the values 0/1.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2
"Erland Sommarskog" <so****@algonet.se> wrote in message news:Xn**********************@127.0.0.1...
Scrappy (ce*****@lan-specialist.com) writes:
I am a SQL newbie! What is the correct datatype to use, if I want to
record a checkbox from a web form? Thanks,
The most natural type to use would be bit, which only can hold the values 0
or 1.

If you want to stick to standards, you may avoid this datatype since it
is propritary to SQL Server and Sybase (or at least so claims Joe Celko).


Hi Erland, actually, BIT, and the more general BIT(n), are defined in both
SQL:1992 and SQL:1999. I believe the difference is that the Standard
requires a bit string literal to be written like B'1'. Not sure if the integer
1 would be automatically cast to B'1' but seems reasonable.

Regards,
jag
In such case a char(1) column with the values T/F ot Y/N could be an
alternative. Or a tinyint column with the values 0/1.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Jul 20 '05 #3
>> the more general BIT(n), are defined in both SQL:1992 and SQL:1999 <<

Yes, and in the Standards, you treat them as if they were character
strings. The operations are bit string comparison, assignment, bit
concatenation operator, bit substring function, length, and position.
You do not have bit-wise operators like you do in T-SQL or assembly
language.

When you try to use them with a host languages, you get all kinds of
problems -- high end or low end bytes? Does 0 or 1 mean "TRUE"?

--CELKO--
===========================
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Thomas Paul Diffenbach | last post: by
4 posts views Thread by Dan | last post: by
4 posts views Thread by toby989 | last post: by
10 posts views Thread by oktayarslan | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.