2015.4.2-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))spa

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' it

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

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

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

相关文章
相关标签/搜索