1)玩具的现有数量应在0到200之间
alter table Toys
add constraint T1 check(siToyQoh between 0 and 200)
(2)玩具适宜的最低年龄缺省为1。(假设年龄列名 为 LowerAge)如何添加约束呀?
alter table Toys
???
在SQL server下运行
alter table Toys
add constraint T1 check(siToyQoh between 0 and 200)
(2)玩具适宜的最低年龄缺省为1。(假设年龄列名 为 LowerAge)如何添加约束呀?
alter table Toys
???
在SQL server下运行
alter table Toys
add constraint T1 check(siToyQoh between 0 and 200) create table toy(siToyQoh int)
go
alter table toy add check(siToyQoh between 0 and 200)
godrop table toy
--如果列LowerAge不存在:
alter table Toys add LowerAge int not null DEFAULT 1 --如果列LowerAge存在:
ALTER TABLE toys ADD CONSTRAINT LowerAge default 1 for LowerAge
ALTER TABLE Toys ADD CONSTRAINT CHK_toy_siToyQoh CHECK(siToyQoh BETWEEN 0 AND 200)
go
ALTER TABLE Toys ADD CONSTRAINT CHK_toy_LowerAge CHECK(LowerAge >= 1)
go