SQL Server 基础之《学生表-教师表-课程表-选课表》

Posted 沐风

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL Server 基础之《学生表-教师表-课程表-选课表》相关的知识,希望对你有一定的参考价值。

表结构

--学生表tblStudent(编号StuId、姓名StuName、年龄StuAge、性别StuSex)

--课程表tblCourse(课程编号CourseId、课程名称CourseName、教师编号TeaId)

--成绩表tblScore(学生编号StuId、课程编号CourseId、成绩Score)

--教师表tblTeacher(教师编号TeaId、姓名TeaName)

技术分享图片
CREATE TABLE tblStudent 
  ( 
     StuId   INT, 
     StuName nvarchar(32), 
     StuAge  INT, 
     StuSex  nvarchar(8) 
  ) 

CREATE TABLE tblCourse 
  ( 
     CourseId    INT, 
     CourseName nvarchar(32), 
     TeaId    INT 
  ) 

CREATE TABLE tblScore 
  ( 
     StuId   INT, 
     CourseId    INT, 
     Score INT 
  ) 

CREATE TABLE tblTeacher 
  ( 
     TeaId    INT, 
     TeaName nvarchar(16) 
  )

  
  insert into tblStudent select 1,N刘一,18,N union all
 select 2,N钱二,19,N union all
 select 3,N张三,17,N union all
 select 4,N李四,18,N union all
 select 5,N王五,17,N union all
 select 6,N赵六,19,N 

 
 insert into tblTeacher select 1,N叶平 union all
 select 2,N贺高 union all
 select 3,N杨艳 union all
 select 4,N周磊
 
 insert into tblCourse select 1,N语文,1 union all
 select 2,N数学,2 union all
 select 3,N英语,3 union all
 select 4,N物理,4
 
 insert into tblScore 
 select 1,1,56 union all 
 select 1,2,78 union all 
 select 1,3,67 union all 
 select 1,4,58 union all 
 select 2,1,79 union all 
 select 2,2,81 union all 
 select 2,3,92 union all 
 select 2,4,68 union all 
 select 3,1,91 union all 
 select 3,2,47 union all 
 select 3,3,88 union all 
 select 3,4,56 union all 
 select 4,2,88 union all 
 select 4,3,90 union all 
 select 4,4,93 union all 
 select 5,1,46 union all 
 select 5,3,78 union all 
 select 5,4,53 union all 
 select 6,1,35 union all 
 select 6,2,68 union all 
 select 6,4,71
View Code

 

 

 

 

 

 

 

https://blog.csdn.net/sujiacheng_123/article/details/53928474

以上是关于SQL Server 基础之《学生表-教师表-课程表-选课表》的主要内容,如果未能解决你的问题,请参考以下文章

sql面试题(学生表_课程表_成绩表_教师表)

sql面试题(学生表_课程表_成绩表_教师表)

mysql数据库面试题(学生表_课程表_成绩表_教师表)

必看,经典sql面试题(学生表_课程表_成绩表_教师表)

MySQL入门篇之高级查询

SQL 45道题