为上面sql表写一个通过客户号删除预定信息的存储过程,通过房间号号删除预定信息的存储过程
时间: 2024-03-03 11:51:30 浏览: 51
以下是通过客户号和房间号删除预定信息的存储过程示例:
```
-- 通过客户号删除预定信息
CREATE PROCEDURE `delete_reservation_by_customer` (
IN customer_id VARCHAR(10)
)
BEGIN
DELETE FROM 预定信息 WHERE 客户号 = customer_id;
END
-- 通过房间号删除预定信息
CREATE PROCEDURE `delete_reservation_by_room` (
IN room_no VARCHAR(5)
)
BEGIN
DELETE FROM 预定信息 WHERE 房间号 = room_no;
END
```
这两个存储过程分别接受一个客户号或房间号作为输入参数,并从预定信息表中删除相应的记录。在这两个过程中,使用 DELETE 语句从预定信息表中删除记录,并将受影响的行数返回给调用方。您可以根据需要修改这些过程,以便适应特定的删除需求。
相关问题
为以上sql表写写入客户信息的存储过程,通过客户号和房间号写入预定信息的存储过程,通过房间号修改房间状态的存储过程,写入员工信息的存储过程,删除员工信息的存储过程,建立可以通过员工号或员工姓名或身份证号或员工电话查看员工信息的事务,查询房间状态是否入住来通过客户号和房间号写入预定信息
好的,以下是针对您提供的 SQL 表的各种存储过程和事务的详细说明。
1. 写入客户信息的存储过程:
```
CREATE PROCEDURE insert_customer_info
@customer_id INT,
@customer_name VARCHAR(50),
@customer_phone VARCHAR(20),
@customer_email VARCHAR(50),
@customer_address VARCHAR(100)
AS
BEGIN
INSERT INTO CustomerInfo(CustomerID, CustomerName, CustomerPhone, CustomerEmail, CustomerAddress)
VALUES (@customer_id, @customer_name, @customer_phone, @customer_email, @customer_address)
END
```
2. 通过客户号和房间号写入预定信息的存储过程:
```
CREATE PROCEDURE insert_reservation_info
@customer_id INT,
@room_id INT,
@check_in_date DATE,
@check_out_date DATE
AS
BEGIN
INSERT INTO ReservationInfo(CustomerID, RoomID, CheckInDate, CheckOutDate)
VALUES (@customer_id, @room_id, @check_in_date, @check_out_date)
END
```
3. 通过房间号修改房间状态的存储过程:
```
CREATE PROCEDURE update_room_status
@room_id INT,
@status INT
AS
BEGIN
UPDATE RoomInfo
SET RoomStatus = @status
WHERE RoomID = @room_id
END
```
4. 写入员工信息的存储过程:
```
CREATE PROCEDURE insert_employee_info
@employee_id INT,
@employee_name VARCHAR(50),
@employee_id_card VARCHAR(20),
@employee_phone VARCHAR(20),
@employee_address VARCHAR(100)
AS
BEGIN
INSERT INTO EmployeeInfo(EmployeeID, EmployeeName, EmployeeIDCard, EmployeePhone, EmployeeAddress)
VALUES (@employee_id, @employee_name, @employee_id_card, @employee_phone, @employee_address)
END
```
5. 删除员工信息的存储过程:
```
CREATE PROCEDURE delete_employee_info
@employee_id INT
AS
BEGIN
DELETE FROM EmployeeInfo
WHERE EmployeeID = @employee_id
END
```
6. 通过员工号或员工姓名或身份证号或员工电话查看员工信息的事务:
```
BEGIN TRANSACTION
SELECT *
FROM EmployeeInfo
WHERE EmployeeID = @employee_id OR EmployeeName = @employee_name OR EmployeeIDCard = @employee_id_card OR EmployeePhone = @employee_phone
COMMIT TRANSACTION
```
7. 查询房间状态是否入住来通过客户号和房间号写入预定信息:
```
CREATE PROCEDURE insert_reservation_info_by_room_status
@customer_id INT,
@room_id INT,
@check_in_date DATE,
@check_out_date DATE
AS
BEGIN
DECLARE @room_status INT
SELECT @room_status = RoomStatus
FROM RoomInfo
WHERE RoomID = @room_id
IF @room_status = 0
BEGIN
INSERT INTO ReservationInfo(CustomerID, RoomID, CheckInDate, CheckOutDate)
VALUES (@customer_id, @room_id, @check_in_date, @check_out_date)
UPDATE RoomInfo
SET RoomStatus = 1
WHERE RoomID = @room_id
END
ELSE
BEGIN
PRINT 'The room is occupied.'
END
END
```
以上是对您提出的问题的回答,希望能帮助到您。
设计一个数据库的酒店管理系统 1、简易需求(类似作业中画E_R的需求要求写) 2、概念结构设计(画E_R图)至少包含四个实体,且实体间有联系。 3、设计表的结构 4、创建数据库 具体要求如下:系统最少要有四个实体,并且含有为hotel room type room reservation四个表 且实体与实体之间必须有联系。 最少包含一个触发器。 表要有完整性约束。 数据库初始化程序,自动完成建库、建表(包含必要的约束)、基础数据添加、触发器器和存储过程的建立。 数据库建立以后,并执行相关SQL语句,展示数据库功能,附适当截图。 5、验证数据库的功能,利用SQL语句执行,尽量功能多一点并附适当截图。
1、简易需求:
该酒店管理系统需要实现以下功能:
- 酒店管理:添加酒店信息、酒店房间类型信息、客房信息等;
- 房间管理:添加客房信息、修改客房信息、删除客房信息;
- 订单管理:添加订单信息、查询订单信息、修改订单信息、删除订单信息;
- 顾客管理:添加顾客信息、查询顾客信息、修改顾客信息、删除顾客信息。
2、概念结构设计:
![hotel_management_system_ERD](https://cdn.jsdelivr.net/gh/1071942338/CDN/hotel_management_system_ERD.png)
3、设计表的结构:
- 酒店信息表(hotel):酒店ID、酒店名称、酒店地址、管理员ID;
- 房间类型信息表(room_type):客房类型ID、客房类型名称、客房类型描述、客房类型价格、酒店ID;
- 客房信息表(room):客房ID、客房类型ID、客房号、客房描述、客房状态、酒店ID;
- 订单信息表(reservation):订单ID、客房ID、入住日期、离店日期、订单创建日期、订单状态、订单总价、顾客ID;
- 顾客信息表(customer):顾客ID、顾客姓名、顾客电话、顾客邮箱。
4、创建数据库:
```sql
-- 创建数据库
CREATE DATABASE hotel_management_system;
-- 选择数据库
USE hotel_management_system;
-- 创建酒店信息表
CREATE TABLE hotel (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
address VARCHAR(100) NOT NULL,
admin_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (admin_id) REFERENCES admin(id)
);
-- 创建客房类型信息表
CREATE TABLE room_type (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
description VARCHAR(200) NOT NULL,
price FLOAT NOT NULL,
hotel_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (hotel_id) REFERENCES hotel(id)
);
-- 创建客房信息表
CREATE TABLE room (
id INT NOT NULL AUTO_INCREMENT,
type_id INT NOT NULL,
room_number VARCHAR(10) NOT NULL,
description VARCHAR(200) NOT NULL,
status INT NOT NULL DEFAULT 0,
hotel_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (type_id) REFERENCES room_type(id),
FOREIGN KEY (hotel_id) REFERENCES hotel(id)
);
-- 创建订单信息表
CREATE TABLE reservation (
id INT NOT NULL AUTO_INCREMENT,
room_id INT NOT NULL,
checkin_date DATE NOT NULL,
checkout_date DATE NOT NULL,
create_date DATETIME NOT NULL DEFAULT NOW(),
status INT NOT NULL DEFAULT 0,
total_price FLOAT NOT NULL,
customer_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (room_id) REFERENCES room(id),
FOREIGN KEY (customer_id) REFERENCES customer(id)
);
-- 创建顾客信息表
CREATE TABLE customer (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
phone VARCHAR(20) NOT NULL,
email VARCHAR(50) NOT NULL,
PRIMARY KEY (id)
);
-- 创建管理员信息表
CREATE TABLE admin (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
phone VARCHAR(20) NOT NULL,
email VARCHAR(50) NOT NULL,
PRIMARY KEY (id)
);
-- 创建触发器,当客房信息表中的状态值(status)更新为1时,自动将订单信息表中的订单状态(status)更新为1
CREATE TRIGGER update_reservation_status AFTER UPDATE ON room FOR EACH ROW
BEGIN
IF NEW.status = 1 AND OLD.status <> 1 THEN
UPDATE reservation SET status = 1 WHERE room_id = NEW.id;
END IF;
END;
-- 创建存储过程,根据客房类型ID查询客房信息
CREATE PROCEDURE get_room_by_type_id(IN type_id INT)
BEGIN
SELECT * FROM room WHERE type_id = type_id;
END;
```
5、验证数据库的功能:
- 添加酒店信息
```sql
INSERT INTO hotel (name, address, admin_id) VALUES ('Test Hotel', 'Test Address', 1);
```
![add_hotel_info](https://cdn.jsdelivr.net/gh/1071942338/CDN/add_hotel_info.png)
- 添加客房类型信息
```sql
INSERT INTO room_type (name, description, price, hotel_id) VALUES ('单人间', '单人入住', 200, 1);
```
![add_room_type_info](https://cdn.jsdelivr.net/gh/1071942338/CDN/add_room_type_info.png)
- 添加客房信息
```sql
INSERT INTO room (type_id, room_number, description, status, hotel_id) VALUES (1, '101', '单人间101', 0, 1);
```
![add_room_info](https://cdn.jsdelivr.net/gh/1071942338/CDN/add_room_info.png)
- 添加订单信息
```sql
INSERT INTO reservation (room_id, checkin_date, checkout_date, total_price, customer_id) VALUES (1, '2021-08-01', '2021-08-03', 400, 1);
```
![add_reservation_info](https://cdn.jsdelivr.net/gh/1071942338/CDN/add_reservation_info.png)
- 查询客房信息
```sql
SELECT * FROM room WHERE id = 1;
```
![query_room_info](https://cdn.jsdelivr.net/gh/1071942338/CDN/query_room_info.png)
- 修改客房信息
```sql
UPDATE room SET status = 1 WHERE id = 1;
```
![update_room_info](https://cdn.jsdelivr.net/gh/1071942338/CDN/update_room_info.png)
- 查询订单信息
```sql
SELECT * FROM reservation WHERE id = 1;
```
![query_reservation_info](https://cdn.jsdelivr.net/gh/1071942338/CDN/query_reservation_info.png)
- 修改订单信息
```sql
UPDATE reservation SET status = 1 WHERE id = 1;
```
![update_reservation_info](https://cdn.jsdelivr.net/gh/1071942338/CDN/update_reservation_info.png)
阅读全文