学生管理系统数据库表sql serve
时间: 2024-12-31 14:02:58 浏览: 17
以下是一个简单的学生管理系统数据库表的SQL Server脚本示例:
```sql
-- 创建数据库
CREATE DATABASE StudentManagementSystem;
GO
USE StudentManagementSystem;
GO
-- 创建学生表
CREATE TABLE Students (
StudentID INT PRIMARY KEY IDENTITY(1,1),
FirstName NVARCHAR(50) NOT NULL,
LastName NVARCHAR(50) NOT NULL,
DateOfBirth DATE NOT NULL,
Gender NVARCHAR(10),
Email NVARCHAR(100) UNIQUE,
Phone NVARCHAR(20),
Address NVARCHAR(200)
);
GO
-- 创建课程表
CREATE TABLE Courses (
CourseID INT PRIMARY KEY IDENTITY(1,1),
CourseName NVARCHAR(100) NOT NULL,
Credits INT NOT NULL,
Description NVARCHAR(500)
);
GO
-- 创建选课表
CREATE TABLE Enrollments (
EnrollmentID INT PRIMARY KEY IDENTITY(1,1),
StudentID INT NOT NULL,
CourseID INT NOT NULL,
EnrollmentDate DATE NOT NULL,
Grade DECIMAL(5,2),
FOREIGN KEY (StudentID) REFERENCES Students(StudentID),
FOREIGN KEY (CourseID) REFERENCES Courses(CourseID)
);
GO
-- 创建教师表
CREATE TABLE Teachers (
TeacherID INT PRIMARY KEY IDENTITY(1,1),
FirstName NVARCHAR(50) NOT NULL,
LastName NVARCHAR(50) NOT NULL,
Email NVARCHAR(100) UNIQUE,
Phone NVARCHAR(20),
HireDate DATE NOT NULL
);
GO
-- 创建授课表
CREATE TABLE Teachings (
TeachingID INT PRIMARY KEY IDENTITY(1,1),
TeacherID INT NOT NULL,
CourseID INT NOT NULL,
Semester NVARCHAR(20) NOT NULL,
Year INT NOT NULL,
FOREIGN KEY (TeacherID) REFERENCES Teachers(TeacherID),
FOREIGN KEY (CourseID) REFERENCES Courses(CourseID)
);
GO
```
这个脚本创建了一个简单的学生管理系统数据库,包括以下表:
1. Students:存储学生信息
2. Courses:存储课程信息
3. Enrollments:存储学生选课信息
4. Teachers:存储教师信息
5. Teachings:存储教师授课信息
各表之间的关系如下:
- Enrollments 表通过 StudentID 和 CourseID 分别与 Students 和 Courses 表关联
- Teachings 表通过 TeacherID 和 CourseID 分别与 Teachers 和 Courses 表关联
这个结构可以根据具体需求进行扩展和修改。
阅读全文