MySQL电影票预定销售系统局部ER图
时间: 2025-01-02 13:42:13 浏览: 15
### MySQL电影票预订销售系统的局部ER图设计
#### 实体关系概述
实体关系图(Entity Relationship Diagram, ERD)用于描述数据库中的表及其之间的关系。对于一个MySQL驱动的电影票预订销售系统而言,主要涉及几个核心实体:`Movie`, `Screening`, `Seat`, `Booking`, 和 `Customer`。
#### 主要实体定义
##### Movie (电影)
- **movie_id**: INT PRIMARY KEY AUTO_INCREMENT
- title: VARCHAR(255) NOT NULL
- release_date: DATE NOT NULL
##### Screening (放映场次)
- **screening_id**: INT PRIMARY KEY AUTO_INCREMENT
- movie_id: INT FOREIGN KEY REFERENCES Movie(movie_id), NOT NULL
- start_time: DATETIME NOT NULL
- end_time AS (start_time + INTERVAL duration_minutes MINUTE)
##### Seat (座位)
- **seat_id**: INT PRIMARY KEY AUTO_INCREMENT
- row_number: TINYINT UNSIGNED NOT NULL
- seat_number: TINYINT UNSIGNED NOT NULL
- theater_id: INT FOREIGN KEY REFERENCES Theater(theater_id), NOT NULL
##### Booking (预定记录)
- **booking_id**: INT PRIMARY KEY AUTO_INCREMENT
- customer_id: INT FOREIGN KEY REFERENCES Customer(customer_id), NOT NULL
- screening_id: INT FOREIGN KEY REFERENCES Screening(screening_id), NOT NULL
- booking_time: TIMESTAMP DEFAULT CURRENT_TIMESTAMP
##### Customer (顾客)
- first_name: VARCHAR(100) NOT NULL
- last_name: VARCHAR(100) NOT NULL
- email: VARCHAR(254) UNIQUE NOT NULL
- phone: CHAR(15)
```sql
CREATE TABLE IF NOT EXISTS Movie (
movie_id INT AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
duration_minutes SMALLINT UNSIGNED NOT NULL,
release_date DATE NOT NULL,
PRIMARY KEY (movie_id)
);
CREATE TABLE IF NOT EXISTS Screening (
screening_id INT AUTO_INCREMENT,
movie_id INT NOT NULL,
start_time DATETIME NOT NULL,
end_time AS (start_time + INTERVAL duration_minutes MINUTE),
PRIMARY KEY (screening_id),
FOREIGN KEY (movie_id) REFERENCES Movie(movie_id)
);
CREATE TABLE IF NOT EXISTS Seat (
seat_id INT AUTO_INCREMENT,
row_number TINYINT UNSIGNED NOT NULL,
seat_number TINYINT UNSIGNED NOT NULL,
theater_id INT NOT NULL,
PRIMARY KEY (seat_id),
FOREIGN KEY (theater_id) REFERENCES Theater(theater_id)
);
CREATE TABLE IF NOT EXISTS Booking (
booking_id INT AUTO_INCREMENT,
customer_id INT NOT NULL,
screening_id INT NOT NULL,
booking_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (booking_id),
FOREIGN KEY (customer_id) REFERENCES Customer(customer_id),
FOREIGN KEY (screening_id) REFERENCES Screening(screening_id)
);
CREATE TABLE IF NOT EXISTS Customer (
customer_id INT AUTO_INCREMENT,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
email VARCHAR(254) UNIQUE NOT NULL,
phone CHAR(15),
PRIMARY KEY (customer_id)
);
```
这些表格共同构成了一个简单的电影票预订销售系统的逻辑模型[^1]。此设计方案考虑到了实际应用场景下的基本需求,并确保了数据的一致性和完整性约束。
阅读全文