很基础的sql语句的使用示例
Create table SC ( )
Sno varchar(7) foreign key references student(Sno), Cno varchar(10) foreign key references course(Cno), Grade int check(Grade between 0 and 100), Primary key (Sno,Cno)
1.查询学生选课表中的全部数据。
SELECT * FROM SC go
2.查询计算机系学生的姓名、年龄。
Select Sname,Sage From Student
Where Sdept=’计算机系’
3.查询成绩在70~80分之间的学生的学号、课程号和成绩。
Select Sno,Cno,Grade From Course,Sc
Where http://www.77cn.com.cno=http://www.77cn.com.cno and sc.Grade between 70 and 80
4.查询计算机系年龄在18~20之间且性别为“男”的学生的
姓名和年龄。
Select Sname,Sage From Student
Where Sage between 18 and 20 and Ssex=’男’and Sdept=’计算机系’ go
5.查询课程号为“C01”的课程的最高分数。
Select top 1 Grade select max(Grade) as 最高分 From Sc from Sc