SQL Server 2008 adding Check Values
I want to allow a column to accept only two 开发者_如何转开发values i.e. Open and Close statuses.How would I go through with it ?
CREATE TABLE Tasks(
ID INT IDENTITY(1,1),
Short_Name VARCHAR(25) NOT NULL,
DateCreated DATETIME NOT NULL,
DateModified DATETIME NULL,
CreatedBy INT NOT NULL,
ModifiedBy INT NULL,
Status VARCHAR(12) DEFAULT('Open') NOT NULL,
Description VARCHAR(255) NULL,
)
Try this
CREATE TABLE Tasks(
ID INT IDENTITY(1,1),
Short_Name VARCHAR(25) NOT NULL,
DateCreated DATETIME NOT NULL,
DateModified DATETIME NULL,
CreatedBy INT NOT NULL,
ModifiedBy INT NULL,
Status VARCHAR(12) DEFAULT('Open') NOT NULL,
Description VARCHAR(255) NULL,
CONSTRAINT chk_status_val CHECK(Status IN ('Open', 'Close'))
)
精彩评论