Sakila——MySQL样例数据库解析

建库建表sql语句

一、Introduction

Sakila可以作为数据库设计的参考,也可作为实验数据。我是用作数据仓库和ODI学习的实验数据。


The Sakila sample database was developed by Mike Hillyer, a former member of the MySQL AB documentation team, andis intended to provide a standard schema that can be used for examples in books, tutorials, articles, samples, and so forth.Sakila sample database also serves to highlight the latest features of MySQL such as Views, Stored Procedures, and Triggers.

二、Installation
方法一:安装MySQL时选择 FULL 完全安装

安装MySQL时选择FULL 完全安装, 默认安装了Sakila sample database


clip_image002clip_image004

方法二:下载后导入

The Sakila sample database is available fromhttp://dev.mysql.com/doc/index-other.html. A downloadable archive is available in compressed file or Zip format. The archive contains three files:sakila-schema.sql,sakila-data.sql, andsakila.mwb.


Thesakila-schema.sqlfile contains all theCREATEstatements required to create the structure of the Sakila database including tables, views, stored procedures, and triggers.


Thesakila-data.sqlfile contains theINSERTstatements required to populate the structure created by thesakila-schema.sqlfile, along with definitions for triggers that must be created after the initial data load.


Thesakila.mwbfile is a MySQL Workbench data model that you can open within MySQL Workbench to examine the database structure. For more information, seeMySQL Workbench.


下载地址:


ZIP格式:http://downloads.mysql.com/docs/sakila-db.zip


tar格式http://downloads.mysql.com/docs/sakila-db.tar.gz


官方文档http://dev.mysql.com/doc/sakila/en/index.html


解压后得到三个文件:


1. sakila-schema.sql 文件包含创建Sakila数据库的结构:表、视图、存储过程和触发器


2. sakila-data.sql文件包含:使用 INSERT语句填充数据及在初始数据加载后,必须创建的触发器的定义


3. sakila.mwb文件是一个MySQL Workbench数据模型,可以在MySQL的工作台打开查看数据库结构。


导入参考:http://dev.mysql.com/doc/sakila/en/sakila-installation.html


shell>mysql -u root -p

mysql> SOURCE C:/temp/sakila-db/sakila-schema.sql;
mysql> SOURCE C:/temp/sakila-db/sakila-data.sql;

查看导入结果


sakila

三、Structure
Sakila样例数据库包括16张表格,7个视图,3个Stored Procedures,3个Functions,6个Triggers。英文描述点开相应连接即可查看。


image


全图:


Customer Data 和 Business Data


Inventory Data


3.1 Tables

3.1.1. The actor Table演员表


3.1.2. The address Table地址表


3.1.3. The category Table电影类别表


3.1.4. The city Table城市表


3.1.5. The country Table国家表


3.1.6. The customer Table客户表


3.1.7. The film Table电影表


3.1.8. The film_actor Table电影和演员中间对应表


3.1.9. The film_category Table电影和类别的中间对应表


3.1.10. The film_text Table只包含title和description两列的电影表子表,用以快速检索


3.1.11. The inventory Table库存表


3.1.12. The language Table语言表


3.1.13. The payment Table付款表


3.1.14. The rental Table租金表


3.1.15. The staff Table工作人员表


3.1.16. The store Table商店表


【01演员表actor】


演员表列出了所有演员的信息。演员表和电影表之间是多对多的关系,通过film_actor表建立关系


1

2

3

4


actor_id: 代理主键用于唯一标识表中的每个演员

first_name: 演员的名字

last_name: 演员的姓氏

last_update: 该行已创建或最近更新的时间


【02地址表address】


地址表包含客户、员工和商店的地址信息。地址表的主键出现在顾客、 员工、和存储表的外键 。


1

2

3

4

5

6

7

8


address_id: 代理主键用于唯一标识表中的每个地址

address: 地址的第一行

address2: 一个可选的第二行地址

district: 该地区的所属地区,这可以是国家,省,县等

city_id: 指向城市表的外键

postal_code: 邮政编码

phone: 地址的电话号码

last_update: 该行已创建或最近更新的时间


【03分类表category】


类别表列出了可以分配到一个电影类别。分类和电影是多对多的关系,通过表film_category建立关系


1

2

3


category_id: 代理主键用于唯一标识表中的每个类别

name: 类别名称

last_update: 该行已创建或最近更新的时间


【04城市表city】


城市表包含的城市名单。城市表使用外键来标示国家;在地址表中被作为外键来使用。


1

2

3

4


city_id: 代理主键用于唯一标识表中的每个城市

city: 城市的名字

country_id: 外键,用于标示城市所属的国家

last_update: 该行已创建或最近更新的时间


【05国家表country】


国家表中包含的国家名单。国家表是指在城市表的外键 。


1

2

3


country_id: 代理主键用于唯一标识表中的每个国家

country: 国家的名称

last_update: 该行已创建或最近更新的时间


【06客户表customer】


客户表包含了所有客户的列表 。 客户表在支付表和租金表被作为外键使用;客户表使用外键来表示地址和存储。


1

2

3

4

5

6

7

8

9


customer_id: 代理主键用于唯一标识表中的每个客户

store_id: 一个外键,确定客户所属的store。

first_name: 客户的名字

last_name: 客户的姓氏

email: 客户的电子邮件地址

address_id: 使用在地址 表的外键来确定客户的地址

active: 表示客户是否是活跃的客户

create_date: 顾客被添加到系统中的日期。使用 INSERT 触发器自动设置。

last_update: 该行已创建或最近更新的时间
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值