开发者

SQL Server 2005 Create Table with Column Default value range

开发者 https://www.devze.com 2023-01-02 11:06 出处:网络
Trying to finish up some homework and ran into a issue for creating tables. How do you declare a column default for a range of numbers. Its reads: \"Column Building (default to 1 but can be 1-10)\"I c

Trying to finish up some homework and ran into a issue for creating tables. How do you declare a column default for a range of numbers. Its reads: "Column Building (default to 1 but can be 1-10)" I can't seem to find ...or know where to look for this informatio开发者_高级运维n.

CREATE TABLE tblDepartment
(
Department_ID int NOT NULL IDENTITY,
Department_Name varchar(255) NOT NULL,
Division_Name varchar(255) NOT NULL,
City varchar(255) default 'spokane' NOT NULL,
Building int default 1 NOT NULL,
Phone varchar(255)
)

I tried Building int default 1 Between 1 AND 10 NOT NULL, that didn't work out I tried Building int default 1-10, the table was created but I don't think its correct.


You need to add CHECK Constraint to the column.

ALTER TABLE tblDepartment
ADD CONSTRAINT chkbuilding CHECK (Building >=1 AND Building <= 10 );
0

精彩评论

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

关注公众号