写一个高校学生宿舍管理系统的数据库,sql server语言实现
时间: 2024-05-13 10:19:00 浏览: 135
创建数据库:
```
CREATE DATABASE DormitoryManagement;
GO
```
创建学生表:
```
USE DormitoryManagement;
GO
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name NVARCHAR(50),
Gender NVARCHAR(10),
Major NVARCHAR(50),
Grade INT,
DormitoryID INT,
FOREIGN KEY (DormitoryID) REFERENCES Dormitories(DormitoryID)
);
GO
```
创建宿舍表:
```
CREATE TABLE Dormitories (
DormitoryID INT PRIMARY KEY,
Building NVARCHAR(50),
RoomNumber INT,
Capacity INT,
Vacancy INT
);
GO
```
创建管理员表:
```
CREATE TABLE Administrators (
AdminID INT PRIMARY KEY,
Name NVARCHAR(50),
Gender NVARCHAR(10),
Position NVARCHAR(50),
DormitoryID INT,
FOREIGN KEY (DormitoryID) REFERENCES Dormitories(DormitoryID)
);
GO
```
创建入住记录表:
```
CREATE TABLE CheckIns (
CheckInID INT PRIMARY KEY,
StudentID INT,
DormitoryID INT,
CheckInDate DATE,
FOREIGN KEY (StudentID) REFERENCES Students(StudentID),
FOREIGN KEY (DormitoryID) REFERENCES Dormitories(DormitoryID)
);
GO
```
创建退宿记录表:
```
CREATE TABLE CheckOuts (
CheckOutID INT PRIMARY KEY,
StudentID INT,
DormitoryID INT,
CheckOutDate DATE,
FOREIGN KEY (StudentID) REFERENCES Students(StudentID),
FOREIGN KEY (DormitoryID) REFERENCES Dormitories(DormitoryID)
);
GO
```
创建维修记录表:
```
CREATE TABLE Repairs (
RepairID INT PRIMARY KEY,
DormitoryID INT,
RequestDate DATE,
Description NVARCHAR(MAX),
Status NVARCHAR(50),
FOREIGN KEY (DormitoryID) REFERENCES Dormitories(DormitoryID)
);
GO
```
创建投诉记录表:
```
CREATE TABLE Complaints (
ComplaintID INT PRIMARY KEY,
StudentID INT,
DormitoryID INT,
ComplaintDate DATE,
Description NVARCHAR(MAX),
Status NVARCHAR(50),
FOREIGN KEY (StudentID) REFERENCES Students(StudentID),
FOREIGN KEY (DormitoryID) REFERENCES Dormitories(DormitoryID)
);
GO
```
阅读全文