给我一个用sql语言实现客房信息管理系统 要求实现功能: (1)客房信息输入和维护:包括每间客房的大小级别、地理位置、租金等信息 (2)客房预订:根据当前客房情况确定预订结果 (3)入住登记:登记客人信息 (4)客房状态查询和统计,房客查询
时间: 2024-01-26 14:03:43 浏览: 75
好的,下面是一个用 SQL 语言实现客房信息管理系统的示例,其中包括您提出的所有要求实现功能:
1. 客房信息输入和维护:
创建客房信息表,包括每间客房的大小级别、地理位置、租金等信息:
```
CREATE TABLE room_info (
room_id INT PRIMARY KEY,
size_level VARCHAR(20),
location VARCHAR(50),
rent DECIMAL(8,2)
);
```
插入客房信息数据:
```
INSERT INTO room_info (room_id, size_level, location, rent)
VALUES
(101, 'Deluxe', 'A1', 800),
(102, 'Standard', 'A2', 500),
(103, 'Superior', 'B1', 600),
(104, 'Standard', 'B2', 500),
(105, 'Deluxe', 'C1', 800),
(106, 'Superior', 'C2', 600);
```
更新客房信息数据:
```
UPDATE room_info
SET rent = 700
WHERE room_id = 103;
```
2. 客房预订:
创建客房预订表,记录客人预订的客房信息:
```
CREATE TABLE room_reservation (
reservation_id INT PRIMARY KEY,
room_id INT,
guest_name VARCHAR(50),
check_in_date DATE,
check_out_date DATE,
CONSTRAINT fk_reservation_room
FOREIGN KEY (room_id)
REFERENCES room_info(room_id)
);
```
插入客房预订数据,根据当前客房情况确定预订结果:
```
INSERT INTO room_reservation (reservation_id, room_id, guest_name, check_in_date, check_out_date)
VALUES
(1, 102, '张三', '2022-03-01', '2022-03-04'),
(2, 104, '李四', '2022-03-02', '2022-03-05');
```
查询客房预订情况,判断客房是否已被预订:
```
SELECT *
FROM room_reservation
WHERE room_id = 101
AND (check_in_date <= '2022-03-05' AND check_out_date >= '2022-03-01');
```
3. 入住登记:
创建客人信息表,记录客人的个人信息:
```
CREATE TABLE guest_info (
guest_id INT PRIMARY KEY,
guest_name VARCHAR(50),
phone_number VARCHAR(20),
id_card_number VARCHAR(20)
);
```
插入客人信息数据:
```
INSERT INTO guest_info (guest_id, guest_name, phone_number, id_card_number)
VALUES
(1, '张三', '13888888888', '123456789012345678');
```
创建入住登记表,记录客人入住的客房信息和入住日期:
```
CREATE TABLE check_in (
check_in_id INT PRIMARY KEY,
guest_id INT,
room_id INT,
check_in_date DATE,
CONSTRAINT fk_checkin_guest
FOREIGN KEY (guest_id)
REFERENCES guest_info(guest_id),
CONSTRAINT fk_checkin_room
FOREIGN KEY (room_id)
REFERENCES room_info(room_id)
);
```
插入入住登记数据:
```
INSERT INTO check_in (check_in_id, guest_id, room_id, check_in_date)
VALUES
(1, 1, 102, '2022-03-01');
```
4. 客房状态查询和统计,房客查询:
查询客房状态,包括客房信息和预订情况:
```
SELECT room_info.room_id, room_info.size_level, room_info.location, room_info.rent, room_reservation.guest_name, room_reservation.check_in_date, room_reservation.check_out_date
FROM room_info
LEFT JOIN room_reservation
ON room_info.room_id = room_reservation.room_id
```
查询客人入住情况,包括客人信息和入住的客房信息:
```
SELECT guest_info.guest_name, guest_info.phone_number, guest_info.id_card_number, room_info.room_id, room_info.size_level, room_info.location, room_info.rent, check_in.check_in_date
FROM guest_info
LEFT JOIN check_in
ON guest_info.guest_id = check_in.guest_id
LEFT JOIN room_info
ON check_in.room_id = room_info.room_id;
```
以上是一个简单的用 SQL 语言实现客房信息管理系统的示例,具体实现方式可能因具体业务需求而有所不同。
阅读全文