python练习题12:数据库基础

练习题1

创建如下表:

mysql练习题.png

练习题一

建表语句
class表

create table class (
cid int primary key auto_increment,
caption varchar(4) not null default ''
)engine=Innodb, charset=utf8;

## 插入值
insert into class (caption) values ("三年二班"), ("一年三班"), ("三年一班");

student表

create table student (
sid int primary key auto_increment,
sname varchar(32) not null default '',
gender char(1) not null default '',
class_id int,
constraint fk_student_class foreign key(class_id) references class(cid)
)engine=Innodb, charset=utf8;

## 插入值
insert into student (sname, gender, class_id) values ("钢蛋", "女", 1), ("铁锤", "女", 1), ("山炮", "男", 2);

teacher表

create table teacher (
tid int primary key auto_increment,
tname varchar(32) not null default ''
)engine=Innodb, charset=utf8;

## 插入值
insert into teacher (tname) values ("波多"), ("苍空"), ("饭岛");

course表

create table course (
cid int primary key auto_increment,
cname varchar(10) not null default '',
teacher_id int,
constraint fk_course_teacher foreign key(teacher_id) references teacher(tid)
)engine=Innodb, charset=utf8;

## 插入值
insert into course (cname, teacher_id) values ("生物", 1), ("体育", 1), ("物理", 2);

score表

create table score (
sid int primary key auto_increment,
student_id int,
course_id int,
number tinyint unsigned,
constraint fk_score_student foreign key(student_id) references student(sid),
constraint fk_score_course foreign key(course_id) references course(cid)
)engine=Innodb, charset=utf8;

## 插入值
insert into score (student_id, 
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值