1、primary key不需要使用CONSTRAINT修饰,如果要指定名称则可以。
2、约束应该放在最后,也就是先定义字段,字段定义完在指定primary key,最后再指定CONSTRAINT。
create table student4(
sno numeric(6),
sname char(20) not null,
sage numeric(3),
primary key(sno),
constraint c1 check(sno between 900000 and 999999),
constraint c3 check(sage <30)
);
这样。
望采纳,谢谢!
你的数据版本是多少,不同版本的写法还是有点区别的,我的是mysql 8.0 这样写是可以执行的
create table student3(
Sno numeric(6) constraint c1 check(Sno between 90000 and 99999),
Sname char(20) not null,
Sage numeric(3) constraint c3 check(Sage<30),
Ssex char(2) constraint check(Ssex in ('男','女'))
);