写一个学生宿舍管理系统MySQL数据库代码
时间: 2024-01-17 19:05:46 浏览: 80
好的,以下是一个简单的学生宿舍管理系统MySQL数据库代码:
```sql
-- 创建学生表
CREATE TABLE students (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
gender VARCHAR(10) NOT NULL,
major VARCHAR(50) NOT NULL,
grade VARCHAR(50) NOT NULL,
dorm_id INT,
PRIMARY KEY (id)
);
-- 创建宿舍表
CREATE TABLE dorms (
id INT NOT NULL AUTO_INCREMENT,
building VARCHAR(50) NOT NULL,
room_number VARCHAR(50) NOT NULL,
capacity INT NOT NULL,
remaining_capacity INT NOT NULL,
PRIMARY KEY (id)
);
-- 创建入住记录表
CREATE TABLE checkin_records (
id INT NOT NULL AUTO_INCREMENT,
student_id INT NOT NULL,
dorm_id INT NOT NULL,
checkin_date DATE NOT NULL,
checkout_date DATE,
PRIMARY KEY (id),
CONSTRAINT fk_student FOREIGN KEY (student_id) REFERENCES students(id),
CONSTRAINT fk_dorm FOREIGN KEY (dorm_id) REFERENCES dorms(id)
);
-- 创建维修记录表
CREATE TABLE repair_records (
id INT NOT NULL AUTO_INCREMENT,
dorm_id INT NOT NULL,
description VARCHAR(1000) NOT NULL,
repair_date DATE NOT NULL,
PRIMARY KEY (id),
CONSTRAINT fk_dorm FOREIGN KEY (dorm_id) REFERENCES dorms(id)
);
```
以上是一个简单的学生宿舍管理系统的MySQL数据库代码,可以根据实际需求进行修改和优化。
阅读全文
相关推荐


















