开发者

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'))
)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜