SQL Server 2005创建表与列默认值范围
试图完成一些作业并遇到创建表格的问题。如何声明一系列数字的列默认值。它的内容是:“Column Building(默认为 1,但可以是 1-10)”我似乎找不到……或不知道在哪里查找此信息。
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)
)
我尝试 Building int default 1 Between 1 AND 10 NOT NULL,但没有成功 我尝试 Building int default 1-10,该表已创建,但我认为它不正确。
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 information.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将CHECK Constraint添加到该列。
You need to add CHECK Constraint to the column.