1、創建數據庫python
create database python charset=utf8;
2、設計班級表結構為id、name、isdelete,編寫創建表的語句
create table classes(
id int unsigned auto_increment primary key not null,
name varchar(10),
isdelete bit default 0);
向班級表中插入數據python1、python2、python3
insert into classes(name) values('python1'),('python2'),('python3');
3、學生表結構設計為:姓名、生日、性別、家鄉,并且學生表與班級表為多對一的關系,寫出創建學生表的語句
這里認為 gender 默認值1是表示男生,isdelete 默認值0表示未刪除
create table students(
id int unsigned auto_increment primary key not null,
name varchar(10) not null,
birthday date,
gender bit default 1,
hometown varchar(20),
clsid int unsigned,
isdelete bit default 0);
4、向學生表中插入數據:這里認為 gender 默認值1是表示男生
? * python1班有郭靖、黃蓉,要求:使用全列插入,一次一值
? * python2班有楊過、小龍女,要求:使用指定列插入,一次一值
? * 未分班的學生有黃藥師、洪七公、洪七婆,要求:使用指定列插入,一次多值
insert into students values(0,'郭靖','2016-1-1',1,'蒙古',1,0);
insert into students values(0,'黃蓉','2016-5-8',0,'桃花島',1,0);
insert into students(name,gender,clsid) values('楊過',1,2);
insert into students(name,clsid) values('小龍女',2);
insert into students(name) values('黃藥師'),('洪七公'),('洪七婆');
5、查詢學生的姓名、生日,如果沒有生日則顯示無
select name,ifnull(birthday,'無') from students;
6、查詢學生的姓名、年齡
select name,year(now()) - year(birthday) as age from students;
7、邏輯刪除洪七婆
update students set isdelete=1 where name='洪七婆'
8、修改洪七公的性別為女(gender為0就是女)
update students set gender=0 where name='洪七公'
9、設計科目表subjects,包括科目名稱
create table subjects(
id int unsigned auto_increment primary key not null,
name varchar(20),
isdelete bit default 0);
10、向表中插入數據,科目名有:python、數據庫、前端
insert into subjects(name) values('python'),('數據庫'),('前端');
11、設計成績表,字段包括:學生id、科目id、成績
create table scores(
id int unsigned auto_increment primary key not null,
score int,
stuid int unsigned,
subid int unsigned);
12、向成績表中添加一些示例數據
insert into scores(score,stuid,subid) values
(100,1,1),(98,1,2),(90,1,3),
(95,2,1),(100,2,2),(98,2,3),
(90,3,1),(80,3,2),(85,3,3),
(70,4,1),(60,4,2),(87,4,3);