Tuesday, March 27, 2012

boolean column

How do you add a boolean column or the best alternative to a SQL Express
database?John wrote:
> How do you add a boolean column or the best alternative to a SQL Express
> database?
There is no boolean column datatype. Instead you could try:
ALTER TABLE tbl
ADD bool CHAR(1) NOT NULL
CONSTRAINT df_tbl_bool DEFAULT 'N'
CONSTRAINT ck_tbl_bool CHECK (bool IN ('Y','N'));
or:
ALTER TABLE tbl
ADD bool BIT NOT NULL
CONSTRAINT df_tbl_bool DEFAULT 0;
The BIT type has the potential advantage that client code can easily
convert it to a boolean type. BIT will also save you a certain amount
of storage if you have more than one such column in a table.
CHAR has the potential to allow a clearer and more meaningful choice of
code and you can easily add further codes in future if you want to.
CHAR also doesn't suffer from the annoying inconsistencies that bug the
BIT type: BIT is a numeric type but not all numeric operations are
permitted.
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Hi,
Alternatively, we can also use bit type for bool columns. The value can
only be 0 or 1.
Sincerely yours,
Charles Wang
Microsoft Online Partner Support
======================================================When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
======================================================This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================|||Charles Wang[MSFT] wrote:
> Hi,
> Alternatively, we can also use bit type for bool columns. The value can
> only be 0 or 1.
> Sincerely yours,
> Charles Wang
> Microsoft Online Partner Support
> ======================================================> When responding to posts, please "Reply to Group" via
> your newsreader so that others may learn and benefit
> from this issue.
> ======================================================> This posting is provided "AS IS" with no warranties, and confers no rights.
> ======================================================
You can use bit datatype. In SQL Server 2005 it also accepts true or
false words in TSQL , which is not supported in SQL Server 2000.
Regards
Amish Shah
http://shahamishm.tripod.com|||> You can use bit datatype. In SQL Server 2005 it also accepts true or
> false words in TSQL , which is not supported in SQL Server 2000.
It is worth noticing that these words are passed as strings, not keywords.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"amish" <shahamishm@.gmail.com> wrote in message
news:1155722099.947111.18380@.p79g2000cwp.googlegroups.com...
> Charles Wang[MSFT] wrote:
>> Hi,
>> Alternatively, we can also use bit type for bool columns. The value can
>> only be 0 or 1.
>> Sincerely yours,
>> Charles Wang
>> Microsoft Online Partner Support
>> ======================================================>> When responding to posts, please "Reply to Group" via
>> your newsreader so that others may learn and benefit
>> from this issue.
>> ======================================================>> This posting is provided "AS IS" with no warranties, and confers no rights.
>> ======================================================> You can use bit datatype. In SQL Server 2005 it also accepts true or
> false words in TSQL , which is not supported in SQL Server 2000.
>
> Regards
> Amish Shah
> http://shahamishm.tripod.com
>sql

No comments:

Post a Comment