#新增表
use k7505
create table student(
stuno int PRIMARY key auto_increment, # PRIMARY key表示主键 auto_increment自增长
stuname varchar(50) not null, # not null不能为空
borndate date ,
address varchar(255)
)
create table result(
id int PRIMARY key auto_increment,
stuno int not null ,
subjectno int not null,
score decimal(5,2)
)
#关键字需要使用 ` 是键盘1 旁边的符号 不是单引号
create table `subject`(
subno int PRIMARY key auto_increment,
subjectname varchar(30) not null
)
#创建一般的默认约束
alter table student
ALTER address set default '光谷'
#创建主外键约束alter table resultadd CONSTRAINT fk_stuno FOREIGN key result(stuno) references student(stuno)
#设置默认时间为当前
alter table student
change borndate borndate timestamp not null default now();
#设置唯一约束
alter table `subject` add CONSTRAINT unique(subjectname);