1
create table book(
Bno char(6) primary key,
Bname varchar(30) not NULL,
Fauthor char(10) not NULL,
Pubtime smalldatetime,
Price decimal(3,1),
)
2
create table bookstore(
Stono char(6) primary key,
Stoname varchar(30) not NULL,
Tel char(8) check (tel like ‘[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]’),
Ad varchar(40),
Postcode char(6),
)
3
create table sell(
Bno char(6) not NULL,
Stono char(6) not NULL,
Stime smalldatetime not NULL,
Sno tinyint check (Sno >= 1),
Primary key(Bno,Stono,Stime),
foreign key (Bno) references book(Bno),
foreign key (Stono) references bookstore(Stono)
)
2)
alter table book
add printnum int check(printnum>=1000)
3)
alter table bookstore
drop column Postcode
4)
alter table sell
drop constraint CK__sell__Sno__398D8EEE(这个是我电脑自动的约束名)
alter table sell
alter column Sno int
alter table sell
add constraint sellcheck check(Sno >=1)
这里如果只用第二个命令会报错
我们去掉约束,再改,然后再添加约束即可
改成我们自定义的约束名,不是系统随机的之后,再更改就不会报错了