sakila-dwh-schema文件

本文介绍了一个基于MySQL的数据仓库(Sakila DWH)的搭建过程,包括了多个维度表如演员、客户、电影等的设计详情,以及事实表如租赁记录的设计。该数据仓库还涉及用户权限配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

sakila-dwh-schema文件
-- MySQL dump 10.13  Distrib 5.1.37, for debian-linux-gnu (i486)
--
-- Host: localhost    Database: sakila_dwh
-- ------------------------------------------------------
-- Server version    5.1.37-1ubuntu5.1

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Current Database: 'sakila_dwh'
--

DROP SCHEMA IF EXISTS sakila_dwh;
CREATE SCHEMA sakila_dwh;
USE sakila_dwh;

--
-- Table structure for table 'dim_actor'
--

DROP TABLE IF EXISTS dim_actor;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE dim_actor (
  actor_key int(10) NOT NULL AUTO_INCREMENT,
  actor_last_update datetime NOT NULL,
  actor_last_name varchar(45) NOT NULL,
  actor_first_name varchar(45) NOT NULL,
  actor_id int(11) NOT NULL,
  PRIMARY KEY (`actor_key`)
) ENGINE=MyISAM AUTO_INCREMENT=201 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table 'dim_customer'
--

DROP TABLE IF EXISTS dim_customer;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE dim_customer (
  customer_key int(8) NOT NULL AUTO_INCREMENT,
  customer_last_update datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
  customer_id int(8) DEFAULT NULL,
  customer_first_name varchar(45) DEFAULT NULL,
  customer_last_name varchar(45) DEFAULT NULL,
  customer_email varchar(50) DEFAULT NULL,
  customer_active char(3) DEFAULT NULL,
  customer_created date DEFAULT NULL,
  customer_address varchar(64) DEFAULT NULL,
  customer_district varchar(20) DEFAULT NULL,
  customer_postal_code varchar(10) DEFAULT NULL,
  customer_phone_number varchar(20) DEFAULT NULL,
  customer_city varchar(50) DEFAULT NULL,
  customer_country varchar(50) DEFAULT NULL,
  customer_version_number smallint(5) DEFAULT NULL,
  customer_valid_from date DEFAULT NULL,
  customer_valid_through date DEFAULT NULL,
  PRIMARY KEY (`customer_key`),
  KEY customer_id (`customer_id`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=601 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table 'dim_date'
--

DROP TABLE IF EXISTS dim_date;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE dim_date (
  date_key int(8) NOT NULL,
  date_value date NOT NULL,
  date_short char(12) NOT NULL,
  date_medium char(16) NOT NULL,
  date_long char(24) NOT NULL,
  date_full char(32) NOT NULL,
  day_in_year smallint(5) NOT NULL,
  day_in_month tinyint(3) NOT NULL,
  is_first_day_in_month char(10) NOT NULL,
  is_last_day_in_month char(10) NOT NULL,
  day_abbreviation char(3) NOT NULL,
  day_name char(12) NOT NULL,
  week_in_year tinyint(3) NOT NULL,
  week_in_month tinyint(3) NOT NULL,
  is_first_day_in_week char(10) NOT NULL,
  is_last_day_in_week char(10) NOT NULL,
  month_number tinyint(3) NOT NULL,
  month_abbreviation char(3) NOT NULL,
  month_name char(12) NOT NULL,
  year2 char(2) NOT NULL,
  year4 smallint(5) NOT NULL,
  quarter_name char(2) NOT NULL,
  quarter_number tinyint(3) NOT NULL,
  year_quarter char(7) NOT NULL,
  year_month_number char(7) NOT NULL,
  year_month_abbreviation char(8) NOT NULL,
  PRIMARY KEY (`date_key`),
  UNIQUE KEY `date` (`date_value`) USING BTREE,
  UNIQUE KEY `date_value` (`date_value`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table 'dim_film'
--

DROP TABLE IF EXISTS dim_film;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE dim_film (
  film_key int(8) NOT NULL AUTO_INCREMENT,
  film_last_update datetime NOT NULL,
  film_title varchar(64) NOT NULL,
  film_description text NOT NULL,
  film_release_year smallint(5) NOT NULL,
  film_language varchar(20) NOT NULL,
  film_original_language varchar(20) NOT NULL,
  film_rental_duration tinyint(3) DEFAULT NULL,
  film_rental_rate decimal(4,2) DEFAULT NULL,
  film_duration int(8) DEFAULT NULL,
  film_replacement_cost decimal(5,2) DEFAULT NULL,
  film_rating_code char(5) DEFAULT NULL,
  film_rating_text varchar(30) DEFAULT NULL,
  film_has_trailers char(4) DEFAULT NULL,
  film_has_commentaries char(4) DEFAULT NULL,
  film_has_deleted_scenes char(4) DEFAULT NULL,
  film_has_behind_the_scenes char(4) DEFAULT NULL,
  film_in_category_action char(4) DEFAULT NULL,
  film_in_category_animation char(4) DEFAULT NULL,
  film_in_category_children char(4) DEFAULT NULL,
  film_in_category_classics char(4) DEFAULT NULL,
  film_in_category_comedy char(4) DEFAULT NULL,
  film_in_category_documentary char(4) DEFAULT NULL,
  film_in_category_drama char(4) DEFAULT NULL,
  film_in_category_family char(4) DEFAULT NULL,
  film_in_category_foreign char(4) DEFAULT NULL,
  film_in_category_games char(4) DEFAULT NULL,
  film_in_category_horror char(4) DEFAULT NULL,
  film_in_category_music char(4) DEFAULT NULL,
  film_in_category_new char(4) DEFAULT NULL,
  film_in_category_scifi char(4) DEFAULT NULL,
  film_in_category_sports char(4) DEFAULT NULL,
  film_in_category_travel char(4) DEFAULT NULL,
  film_id int(11) NOT NULL,
  PRIMARY KEY (`film_key`)
) ENGINE=MyISAM AUTO_INCREMENT=1001 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table 'dim_film_actor_bridge'
--

DROP TABLE IF EXISTS dim_film_actor_bridge;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE dim_film_actor_bridge (
  film_key int(8) NOT NULL,
  actor_key int(10) NOT NULL,
  actor_weighting_factor decimal(3,2) NOT NULL,
  PRIMARY KEY (`film_key`,`actor_key`),
  KEY dim_actor_dim_film_actor_bridge_fk (`actor_key`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table 'dim_staff'
--

DROP TABLE IF EXISTS dim_staff;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE dim_staff (
  staff_key int(8) NOT NULL AUTO_INCREMENT,
  staff_last_update datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
  staff_first_name varchar(45) DEFAULT NULL,
  staff_last_name varchar(45) DEFAULT NULL,
  staff_id int(8) DEFAULT NULL,
  staff_store_id int(8) DEFAULT NULL,
  staff_version_number smallint(5) DEFAULT NULL,
  staff_valid_from date DEFAULT NULL,
  staff_valid_through date DEFAULT NULL,
  staff_active char(3) DEFAULT NULL,
  PRIMARY KEY (`staff_key`),
  KEY staff_id (`staff_id`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table 'dim_store'
--

DROP TABLE IF EXISTS dim_store;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE dim_store (
  store_key int(8) NOT NULL AUTO_INCREMENT,
  store_last_update datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
  store_id int(8) DEFAULT NULL,
  store_address varchar(64) DEFAULT NULL,
  store_district varchar(20) DEFAULT NULL,
  store_postal_code varchar(10) DEFAULT NULL,
  store_phone_number varchar(20) DEFAULT NULL,
  store_city varchar(50) DEFAULT NULL,
  store_country varchar(50) DEFAULT NULL,
  store_manager_staff_id int(8) DEFAULT NULL,
  store_manager_first_name varchar(45) DEFAULT NULL,
  store_manager_last_name varchar(45) DEFAULT NULL,
  store_version_number smallint(5) DEFAULT NULL,
  store_valid_from date DEFAULT NULL,
  store_valid_through date DEFAULT NULL,
  PRIMARY KEY (`store_key`),
  KEY store_id (`store_id`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table 'dim_time'
--

DROP TABLE IF EXISTS dim_time;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE dim_time (
  time_key int(8) NOT NULL,
  time_value time NOT NULL,
  hours24 tinyint(3) NOT NULL,
  hours12 tinyint(3) DEFAULT NULL,
  minutes tinyint(3) DEFAULT NULL,
  seconds tinyint(3) DEFAULT NULL,
  am_pm char(3) DEFAULT NULL,
  PRIMARY KEY (`time_key`),
  UNIQUE KEY time_value (`time_value`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table 'fact_rental'
--

DROP TABLE IF EXISTS fact_rental;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE fact_rental (
  customer_key int(8) NOT NULL,
  staff_key int(8) NOT NULL,
  film_key int(8) NOT NULL,
  store_key int(8) NOT NULL,
  rental_date_key int(8) NOT NULL,
  return_date_key int(10) NOT NULL,
  rental_time_key int(8) NOT NULL,
  count_returns int(10) NOT NULL,
  count_rentals int(8) NOT NULL,
  rental_duration int(11) DEFAULT NULL,
  rental_last_update datetime DEFAULT NULL,
  rental_id int(11) DEFAULT NULL,
  KEY dim_store_fact_rental_fk (`store_key`),
  KEY dim_staff_fact_rental_fk (`staff_key`),
  KEY dim_time_fact_rental_fk (`rental_time_key`),
  KEY dim_film_fact_rental_fk (`film_key`),
  KEY dim_date_fact_rental_fk (`rental_date_key`),
  KEY dim_customer_fact_rental_fk (`customer_key`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2010-03-04  1:00:33

创建用户:

CREATE USER sakila IDENTIFIED BY 'sakila';
GRANT ALL PRIVILEGES ON sakila.* TO sakila;

CREATE USER sakila_dwh IDENTIFIED BY 'sakila_dwh';
GRANT ALL PRIVILEGES ON sakila_dwh.* TO sakila_dwh;


### Sakila 数据库概述 Sakila 示例数据库是使用最广泛且评价最高的示例数据库之一[^1]。该数据库最初由 MySQL AB 文档团队的前成员 Mike Hillyer 开发,旨在为书籍、教程、文章等提供标准化的数据结构用于示例演示。 ### 下载与安装 为了获取并设置 Sakila 数据库,需先下载其 SQL 文件。通常可以从官方 MySQL 网站找到这些文件。下载完成后,在命令行工具中执行如下操作来创建和填充数据库: ```sql SOURCE /path/to/sakila-schema.sql; SOURCE /path/to/sakila-data.sql; ``` 上述路径应替换为实际存储位置,例如 `/Users/用户名/Desktop/sakila-db/sakila-schema.sql`[^3]。 ### 创建用户权限配置 完成数据导入之后,建议为新建立的 Sakila 数据库创建专用账户以增强安全性。通过以下 SQL 命令可以实现这一目标: ```sql CREATE USER 'sakila_dwh'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON sakila.* TO 'sakila_dwh'@'localhost'; FLUSH PRIVILEGES; ``` 这里 `your_password` 应被替换成自定义的安全密码字符串,而 `'sakila_dwh'@'localhost'` 则代表新建用户的名称及其允许连接的位置[^2]。 ### 使用实例 假设要查询所有电影列表以及它们对应的分类名,则可以通过下面这段 SQL 查询语句达成目的: ```sql SELECT f.title, c.name FROM film AS f JOIN film_category AS fc ON f.film_id = fc.film_id JOIN category AS c ON fc.category_id = c.category_id ORDER BY f.title ASC LIMIT 0 , 30 ; ``` 此查询会返回最多三十条记录,每一条都包含了影片标题与其所属类别名称,并按照字母顺序排列。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值