Sakila 数据库:表结构和模式概述
Sakila 是 MySQL 为学习和演示 SQL 及关系数据库管理系统 (RDBMS) 功能而设计的示例关系数据库。
本页面展示了 Sakila 的表结构、关键列和在教育 SQL 查询中常用的约束。
Sakila 数据库包含 15 个主要表,描述了 DVD 租赁公司的各个方面。
Sakila 数据库的 ER 图
了解更多 Sakila 数据库:模式、示例查询和全部练习 →
表列表
actor - 演员表。
- actor_id唯一记录标识符 (PK)
- first_name演员的名字
- last_name演员的姓氏
- last_update最后更新时间
| actor_id |
first_name |
last_name |
last_update |
| 1 |
John |
Doe |
2023-01-01 12:00:00 |
address - 客户和员工地址。
- address_id唯一记录标识符 (PK)
- address邮政地址
- address2附加地址
- district地区或区域
- city_id城市标识符 (FK)
- postal_code邮政编码
- phone电话号码
- last_update最后更新时间
| address_id |
address |
address2 |
district |
city_id |
postal_code |
phone |
last_update |
| 1 |
123 Main St |
[null] |
市中心 |
1 |
12345 |
+1234567890 |
2023-01-01 12:00:00 |
- 外键 (city_id) 参考 city(city_id)
category - 电影类别。
- category_id唯一记录标识符 (PK)
- name类别名称
- last_update最后更新时间
| category_id |
name |
last_update |
| 1 |
动作 |
2023-01-01 12:00:00 |
city - 城市表。
- city_id唯一记录标识符 (PK)
- city城市名称
- country_id国家标识符 (FK)
- last_update最后更新时间
| city_id |
city |
country_id |
last_update |
| 1 |
大都会 |
1 |
2023-01-01 12:00:00 |
- 外键 (country_id) 参考 country(country_id)
country - 国家表。
- country_id唯一记录标识符 (PK)
- country国家名称
- last_update最后更新时间
| country_id |
country |
last_update |
| 1 |
美国 |
2023-01-01 12:00:00 |
customer - 客户表。
- customer_id唯一记录标识符 (PK)
- store_id商店标识符 (FK)
- first_name客户的名字
- last_name客户的姓氏
- email客户的电子邮件地址
- address_id地址标识符 (FK)
- active客户活动指示器 (0/1)
- create_date客户添加到数据库的日期和时间
- last_update最后更新时间
| customer_id |
store_id |
first_name |
last_name |
email |
address_id |
active |
create_date |
last_update |
| 1 |
1 |
John |
Doe |
john.doe@example.com |
1 |
1 |
2023-01-01 12:00:00 |
2023-01-01 12:00:00 |
- 外键 (store_id) 参考 store(store_id)
- 外键 (address_id) 参考 address(address_id)
film - 电影表。
- film_id唯一记录标识符 (PK)
- title电影标题
- description电影的简要描述或情节
- release_year电影发行年份
- language_id电影语言的标识符 (FK)
- original_language_id原始语言的标识符,以防它被配音成新语言
- rental_duration租赁期的天数
- rental_rate租赁电影的费用,持续时间在 rental_duration 列中指定
- length电影长度(分钟)
- replacement_cost丢失或损坏光盘的罚款金额
- rating分配给电影的评级。可以是:G、PG、PG-13、R 或 NC-17
- special_featuresDVD 上包含的特殊功能列表。可以是零个或多个:预告片、评论、删减片段、幕后花絮
- last_update最后更新时间
| film_id |
title |
description |
release_year |
language_id |
original_language_id |
rental_duration |
rental_rate |
length |
replacement_cost |
rating |
special_features |
last_update |
| 1 |
电影标题 |
电影的简要描述。 |
2000 |
1 |
2 |
5 |
4.99 |
120 |
19.99 |
PG-13 |
预告片、评论 |
2023-01-01 12:00:00 |
- 外键 (language_id) 参考 language(language_id)
- 外键 (original_language_id) 参考 language(language_id)
film_actor - 演员与电影的关系。
- actor_id演员标识符 (FK)
- film_id电影标识符 (FK)
- last_update最后更新时间
| actor_id |
film_id |
last_update |
| 1 |
1 |
2023-01-01 12:00:00 |
- 主键,btree (actor_id, film_id)
- 外键 (actor_id) 参考 actor(actor_id)
- 外键 (film_id) 参考 film(film_id)
film_category - 电影与类别的关系。
- film_id电影标识符 (FK)
- category_id类别标识符 (FK)
- last_update最后更新时间
| film_id |
category_id |
last_update |
| 1 |
1 |
2023-01-01 12:00:00 |
- 主键,btree (film_id, category_id)
- 外键 (film_id) 参考 film(film_id)
- 外键 (category_id) 参考 category(category_id)
inventory - 各门店的光盘库存。
- inventory_id唯一记录标识符 (PK)
- film_id电影标识符 (FK)
- store_id光盘所在商店的标识符 (FK)
- last_update最后更新时间
| inventory_id |
film_id |
store_id |
last_update |
| 1 |
23 |
2 |
2023-01-01 12:00:00 |
- 外键 (film_id) 参考 film(film_id)
- 外键 (store_id) 参考 store(store_id)
language - 电影语言。
- language_id唯一记录标识符 (PK)
- name语言名称
- last_update最后更新时间
| language_id |
name |
last_update |
| 1 |
English |
2023-01-01 12:00:00 |
payment - 客户付款。
- payment_id唯一记录标识符 (PK)
- customer_id客户标识符 (FK)
- staff_id收款员工的标识符 (FK)
- rental_id租赁记录标识符 (FK)
- amount付款金额
- payment_date付款日期和时间
- last_update最后更新时间
| payment_id |
customer_id |
staff_id |
rental_id |
amount |
payment_date |
last_update |
| 1 |
1 |
1 |
1 |
4.99 |
2023-01-01 12:13:14 |
2023-01-01 12:14:15 |
- 外键 (customer_id) 参考 customer(customer_id)
- 外键 (staff_id) 参考 staff(staff_id)
- 外键 (rental_id) 参考 rental(rental_id)
rental - 客户租赁记录。
- rental_id唯一记录标识符 (PK)
- rental_date租赁开始日期
- inventory_id光盘标识符 (FK)
- customer_id客户标识符 (FK)
- return_date电影归还日期
- staff_id出租光盘的员工标识符 (FK)
- last_update最后更新时间
| rental_id |
rental_date |
inventory_id |
customer_id |
return_date |
staff_id |
last_update |
| 1 |
2023-01-01 16:15:21 |
1 |
1 |
2023-01-10 09:12:36 |
1 |
2023-01-01 12:00:00 |
- 外键 (inventory_id) 参考 inventory(inventory_id)
- 外键 (customer_id) 参考 customer(customer_id)
- 外键 (staff_id) 参考 staff(staff_id)
staff - 公司员工。
- staff_id唯一记录标识符 (PK)
- first_name员工的名字
- last_name员工的姓氏
- address_id地址标识符 (FK)
- picture员工照片
- email员工的电子邮件地址
- store_id商店标识符 (FK)
- active员工活动指示器 (0/1)
- username系统登录用户名
- password登录密码
- last_update最后更新时间
| staff_id |
first_name |
last_name |
address_id |
picture |
email |
store_id |
active |
username |
password |
last_update |
| 1 |
John |
Doe |
1 |
[null] |
john.doe@example.com |
1 |
1 |
johndoe |
******** |
2023-01-01 12:00:00 |
- 外键 (address_id) 参考 address(address_id)
- 外键 (store_id) 参考 store(store_id)
store - 公司门店。
- store_id唯一记录标识符 (PK)
- manager_staff_id商店经理标识符 (FK)
- address_id地址标识符 (FK)
- last_update最后更新时间
| store_id |
manager_staff_id |
address_id |
last_update |
| 1 |
1 |
1 |
2023-01-01 12:00:00 |
- 外键 (manager_staff_id) 参考 staff(staff_id)
- 外键 (address_id) 参考 address(address_id)