Tags: alternative, boolean, column, database, microsoft, mysql, oracle, server, sql

boolean column

On Database » Microsoft SQL Server

4,169 words with 4 Comments; publish: Sat, 24 May 2008 09:30:00 GMT; (25092.77, « »)

How do you add a boolean column or the best alternative to a SQL Express

database?

All Comments

Leave a comment...

  • 4 Comments
    • 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

      --

      #1; Sat, 24 May 2008 09:31:00 GMT
    • 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.

      ========================================

      ==============

      #2; Sat, 24 May 2008 09:32:00 GMT
    • 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

      #3; Sat, 24 May 2008 09:33:00 GMT
    • > 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.sqlserver.todaysummary.com.gmail.com> wrote in message

      news:1155722099.947111.18380.sqlserver.todaysummary.com.p79g2000cwp.googlegroups.com...

      > Charles Wang[MSFT] wrote:

      >

      > 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

      >

      #4; Sat, 24 May 2008 09:34:00 GMT