用数据库设计代码学生宿舍管理系统设计包括建立宿舍管理系统数据库 包括·宿舍基本信息表 ,专业基本信息表 ,学生基本信息表 ,住宿费用表 ,物品卫生信息管理表和学生信息表:
时间: 2024-02-19 15:04:13 浏览: 92
以下是一个简单的MySQL数据库设计代码,实现了上述六个表和它们之间的关系:
```sql
-- 创建宿舍基本信息表
CREATE TABLE dormitory (
dormitory_id INT NOT NULL AUTO_INCREMENT,
building_number INT NOT NULL,
room_number INT NOT NULL,
bed_number INT NOT NULL,
manager_name VARCHAR(50) NOT NULL,
manager_phone VARCHAR(20) NOT NULL,
PRIMARY KEY (dormitory_id)
);
-- 创建专业基本信息表
CREATE TABLE major (
major_id INT NOT NULL AUTO_INCREMENT,
major_name VARCHAR(50) NOT NULL,
college_id INT NOT NULL,
PRIMARY KEY (major_id)
);
-- 创建学生基本信息表
CREATE TABLE student (
student_id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
gender VARCHAR(10) NOT NULL,
birth_date DATE NOT NULL,
id_card VARCHAR(18) NOT NULL,
phone VARCHAR(20) NOT NULL,
address VARCHAR(100) NOT NULL,
major_id INT NOT NULL,
class_id INT NOT NULL,
dormitory_id INT NOT NULL,
PRIMARY KEY (student_id),
CONSTRAINT fk_student_major FOREIGN KEY (major_id) REFERENCES major(major_id),
CONSTRAINT fk_student_dormitory FOREIGN KEY (dormitory_id) REFERENCES dormitory(dormitory_id)
);
-- 创建住宿费用表
CREATE TABLE accommodation_cost (
dormitory_id INT NOT NULL,
start_date DATE NOT NULL,
end_date DATE NOT NULL,
amount DECIMAL(10,2) NOT NULL,
is_paid BOOLEAN NOT NULL,
PRIMARY KEY (dormitory_id, start_date),
CONSTRAINT fk_cost_dormitory FOREIGN KEY (dormitory_id) REFERENCES dormitory(dormitory_id)
);
-- 创建物品卫生信息管理表
CREATE TABLE cleanliness (
dormitory_id INT NOT NULL,
date DATE NOT NULL,
item_name VARCHAR(50) NOT NULL,
item_quantity INT NOT NULL,
remark VARCHAR(200),
PRIMARY KEY (dormitory_id, date, item_name),
CONSTRAINT fk_clean_dormitory FOREIGN KEY (dormitory_id) REFERENCES dormitory(dormitory_id)
);
-- 创建学生信息表
CREATE TABLE occupancy (
student_id INT NOT NULL,
dormitory_id INT NOT NULL,
check_in_date DATE NOT NULL,
check_out_date DATE,
is_checked_out BOOLEAN NOT NULL,
PRIMARY KEY (student_id, dormitory_id),
CONSTRAINT fk_occupancy_student FOREIGN KEY (student_id) REFERENCES student(student_id),
CONSTRAINT fk_occupancy_dormitory FOREIGN KEY (dormitory_id) REFERENCES dormitory(dormitory_id)
);
```
以上代码可以在MySQL数据库中执行,创建一个包括宿舍基本信息表、专业基本信息表、学生基本信息表、住宿费用表、物品卫生信息管理表和学生信息表的学生宿舍管理系统数据库。
阅读全文