faqts : Computers : Programming : Languages : Asp : ASP/VBScript : Database Backed Sites

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

27 of 39 people (69%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

I want to create a table using sql statement, what is the correct syntax for a boolean field?

Jul 21st, 2000 22:16
unknown unknown, Bruce Anwyl


You can use bit but if you search long enough through SQL Server
documentation you will find that the bit type is not recommended for 
this any more. Instead use a char(1) field with the value 'Y' for true 
and 'N' for false and put a constraint on the table to restrict the 
values.
CREATE TABLE [dbo].[AdditionalCharge] (
[AdditionalChargeID] [int] IDENTITY (1, 1) NOT NULL ,
[DateCharged] [smalldatetime] NOT NULL ,
[CustomerID] [int] NOT NULL ,
[Invoiced] [char] (1) NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[AdditionalCharge] WITH NOCHECK ADD
CONSTRAINT [DF_AdditionalCharge_Invoiced] DEFAULT ('N') FOR [Invoiced] ,
CONSTRAINT [CK_AdditionalCharge_Invoiced] CHECK ([Invoiced] = 'N' or
[Invoiced] = 'Y')
GO



© 1999-2004 Synop Pty Ltd