2015.4.2-SQL 简单语句(一)

本文介绍了如何使用SQL创建学生信息、课程信息及选课记录三个表,并提供了具体示例。此外,还展示了如何进行常见查询操作,如按条件筛选学生信息、统计学生选课数量等。

1.创建一个student表 create table student_masen( sno char(4) not null primarykey sname nchar(10) not null sex char(1) null check('M','F') age smallint null check(age>15 and age<25))

2.创建一个course表 create table course_masen( cno char(4) not null primarykey cname char(10) not null credit smallint null check(credit>0 and credit<10))

3.创建一个S_C表 create table S_C_masen( sno char(4) not null cnno char(4) not null primarykey(sno,cno) grade smallint check(grade>=0 and grade<=100)) alter table s_C_masen add constraint fk_sno foreign key(sno) references student_masen(sno) alter table s_C_masen add constraint fk_cno foreign key(cno) references sutdent_masen(cno)

1.查询性别不是男的学生的姓名 select sname from student_masen where sex!='M'

2.查询性别是男的 年龄大于20的学生姓名 select sname from student_masen where sex='M' and age>20

3.按照课程号降序排列 课程名升序排序 查询出结果集 select * from course_masen order by cno desc ,cname asc

4.在S_C表中,查询学号是S1的学生 一共修了几门课程 select count(cno) from S_C_masen where sno='s1' 通过这次的练习,使我加深了对创建数据库表的理解,继续努力!

转载于:https://www.cnblogs.com/ma-s-e-n-11/p/4389115.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值