sql学生成绩管理系统代码
时间: 2024-06-30 10:01:09 浏览: 156
学生成绩管理系统代码
创建一个简单的SQL学生成绩管理系统代码示例通常包括以下几个步骤和表结构定义。这里假设我们有学生表(Students)、课程表(Courses)和成绩表(Grades)。这是一种基本的结构,实际应用可能需要更多的表来处理更复杂的数据。
```sql
-- 创建学生表 (Students)
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(100),
Class INT,
Department VARCHAR(100)
);
-- 创建课程表 (Courses)
CREATE TABLE Courses (
CourseID INT PRIMARY KEY,
CourseName VARCHAR(100),
Teacher VARCHAR(100),
Department VARCHAR(100)
);
-- 创建成绩表 (Grades)
CREATE TABLE Grades (
GradeID INT PRIMARY KEY,
StudentID INT,
CourseID INT,
Score INT,
FOREIGN KEY (StudentID) REFERENCES Students(StudentID),
FOREIGN KEY (CourseID) REFERENCES Courses(CourseID)
);
```
-- 增加学生信息
INSERT INTO Students (StudentID, Name, Class, Department) VALUES (1, '张三', 1, '计算机科学');
INSERT INTO Students (StudentID, Name, Class, Department) VALUES (2, '李四', 2, '数学系');
-- 增加课程信息
INSERT INTO Courses (CourseID, CourseName, Teacher, Department) VALUES (1, '数据库', '王老师', '计算机科学');
INSERT INTO Courses (CourseID, CourseName, Teacher, Department) VALUES (2, '线性代数', '刘老师', '数学系');
-- 添加成绩
INSERT INTO Grades (GradeID, StudentID, CourseID, Score) VALUES (1, 1, 1, 90);
INSERT INTO Grades (GradeID, StudentID, CourseID, Score) VALUES (2, 1, 2, 85);
INSERT INTO Grades (GradeID, StudentID, CourseID, Score) VALUES (3, 2, 1, 95);
-- 查询学生成绩
SELECT Students.Name, Courses.CourseName, Grades.Score
FROM Students
JOIN Grades ON Students.StudentID = Grades.StudentID
JOIN Courses ON Courses.CourseID = Grades.CourseID
WHERE Students.Department = '计算机科学';
--
阅读全文