数据库查询练习

mysql查询练习

学生表 student ,学号 ,姓名,性别,出生年月日 ,所在班级

create table student(
   sno varchar(20) primary key,
   sname varchar(20) not null,
   ssex varchar(10)not null,
     sbirthday datetime,
   class varchar(20)
)

课程表 course,课程号,课程名称,教室编号

create table course(
   cno VARCHAR(20) primary KEY,
   cname varchar(20) not null,
   tno VARCHAR(20) not null,
   foreign key(tno) REFERENCES teacher(tno)
)

成绩表 score ,学号 ,课程号 ,成绩

create table score(
   sno VARCHAR(20) primary key,
   cno varchar(20) not null,
   degree DECIMAL,
   foreign key(sno) REFERENCES student(sno),
   foreign key(cno) REFERENCES course(cno)

   primary key(sno,cno)
)

教师表

teacher ,教师编号 ,教师名字,教师性别,出身年月日,职称 ,所在部门

create table teacher(
   tno varchar(20) primary KEY,
    tname varchar(20) not null,
    tsex VARCHAR(10) not null,
    tbirthday datetime,
    prof VARCHAR(20) not null,
    depart VARCHAR(20) not null
)

往数据表中添加数据

添加表信息

insert INTO student VALUES('3','li','nan','1999-1-1','95033')

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
create table sailors( sid char(10) primary key, sname char(20), rating int, age int); create table boats( bid char(10) primary key, bname char(20), color char(10)); create table reserves( sid char(10) , bid char(10) , rdate date, primary key(sid,bid,rdate), foreign key (sid) references sailors(sid) on delete cascade, foreign key (bid) references boats(bid) on delete cascade); insert into sailors(sid,sname,rating,age) values("22","dustin",7,45) ("29","brustus",1,33), ("31","lubber",8,56), ("32","andy",8,26), ("58","rusty",10,35), ("64","horatio",7,35), ("71","zorba",10,35), ("74","horatio",9,35), ("85","art",3,26), ("86","john",1,17), ("95","bob",3,64), ("96","frodo",3,26), ("98","tom",3,17); insert into boats(bid,bname,color) values("101","A","red"), ("102","B","green"), ("103","C","blue"), ("104","D","white") ("105","E","red"), ("106","F","blue"), ("107","G","green"); insert into reserves(sid,bid,rdata) values("22","101","2010-01-08"), ("22","102","2010-01-09"), ("29","103","2010-01-09"), ("31","102","2010-02-11"), ("22","104","2010-03-08"), ("22","103","2010-03-10"), ("32","105","2010-03-11"), ("32","106","2010-03-18"), ("32","102","2010-03-19"), ("58","104","2010-03-20"), ("64","105","2010-03-20"), ("95","101","2010-04-02"), ("85","102","2010-04-05"), ("22","101","2010-04-07"), ("22","105","2010-05-01"), ("22","106","2010-06-18"), ("22","107","2010-07-09"), ("31","106","2010-08-06"), ("32","105","2010-08-06"), ("29","104","2010-08-07"), ("64","103","2010-09-05"), ("58","102","2010-09-09"), ("64","104","2010-11-03"), ("64","105","2010-11-04"), ("31","106","2010-12-0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值