本教學向您介紹Oracle範例資料庫,並提供連結供下載。
我們為您提供一個名為 OT 的Oracle範例資料庫,它基於全球虛擬公司,銷售計算機硬體,包括儲存,主機板,RAM,視訊卡和CPU。
公司儲存產品資訊,如:名稱,描述標準成本,標價,產品線。它還跟蹤所有產品的庫存資訊,包括產品可用的倉庫。由於該公司在全球運營,因此在世界各地擁有倉庫。
公司記錄所有客戶資訊,包括姓名,地址和網站。 每個客戶至少有一個聯絡人,包括姓名,電子郵件和電話等詳細資訊。公司還對每位客戶設定了信用限額,以限制客戶可能欠的金額。
只要客戶發出採購訂單,就會在資料庫中建立具有待處理狀態的銷售訂單。當公司運送訂單時,訂單狀態變成 - 運送。如果客戶取消訂單,則訂單狀態將被 - 取消。
除銷售資訊外,員工資料還記錄了一些基本資訊,如姓名,電子郵件,電話,職位,經理和雇用日期。
以下舉例說明範例資料庫圖表:
表名稱 | 描述 | 記錄 |
---|---|---|
contact |
儲存客戶的聯絡人資訊 | 319 條記錄 |
countries |
儲存國家資訊 | 25 條記錄 |
customers |
儲存客戶的資訊 | 319 條記錄 |
employees |
儲存員工的資訊 | 107 條記錄 |
inventories |
儲存產品的庫存資訊 | 1112 條記錄 |
locations |
倉庫的地點 | 23 條記錄 |
orders |
儲存訂單主要資訊 | 105 條記錄 |
order_items |
儲存訂單行專案 | 665 條記錄 |
product_categories |
儲存產品類別 | 5 條記錄 |
products |
儲存產品資訊 | 288 條記錄 |
regions |
儲存公司經營的地區 | 4 條記錄 |
warehouses |
儲存倉庫資訊 | 9 條記錄 |
以zip檔案格式下載以下範例資料庫:
下載檔案後,然後提取它。該zip檔案包含以下的SQL檔案:
以上檔案可通過加入 Oracle資料庫技術QQ群(175248146),從群檔案裡找到範例資料庫(oraok.com)_11g.v1.zip檔案並下載。
以下是用於建立資料庫物件的語句。
-- regions
CREATE TABLE regions
(
region_id NUMBER GENERATED BY DEFAULT AS IDENTITY
START WITH 5 PRIMARY KEY,
region_name VARCHAR2( 50 ) NOT NULL
);
-- countries table
CREATE TABLE countries
(
country_id CHAR( 2 ) PRIMARY KEY ,
country_name VARCHAR2( 40 ) NOT NULL,
region_id NUMBER ,
CONSTRAINT fk_countries_regions FOREIGN KEY( region_id ) REFERENCES regions( region_id ) ON DELETE CASCADE
);
-- location
CREATE TABLE locations
(
location_id NUMBER GENERATED BY DEFAULT AS IDENTITY START WITH 24
PRIMARY KEY ,
address VARCHAR2( 255 ) NOT NULL,
postal_code VARCHAR2( 20 ) ,
city VARCHAR2( 50 ) ,
state VARCHAR2( 50 ) ,
country_id CHAR( 2 ) ,
CONSTRAINT fk_locations_countries
FOREIGN KEY( country_id )
REFERENCES countries( country_id )
ON DELETE CASCADE
);
-- warehouses
CREATE TABLE warehouses
(
warehouse_id NUMBER
GENERATED BY DEFAULT AS IDENTITY START WITH 10
PRIMARY KEY,
warehouse_name VARCHAR( 255 ) ,
location_id NUMBER( 12, 0 ),
CONSTRAINT fk_warehouses_locations FOREIGN KEY( location_id ) REFERENCES locations( location_id ) ON DELETE CASCADE
);
-- employees
CREATE TABLE employees
(
employee_id NUMBER
GENERATED BY DEFAULT AS IDENTITY START WITH 108
PRIMARY KEY,
first_name VARCHAR( 255 ) NOT NULL,
last_name VARCHAR( 255 ) NOT NULL,
email VARCHAR( 255 ) NOT NULL,
phone VARCHAR( 50 ) NOT NULL ,
hire_date DATE NOT NULL ,
manager_id NUMBER( 12, 0 ) ,
job_title VARCHAR( 255 ) NOT NULL,
CONSTRAINT fk_employees_manager FOREIGN KEY( manager_id ) REFERENCES employees( employee_id ) ON DELETE CASCADE
);
-- product category
CREATE TABLE product_categories
(
category_id NUMBER
GENERATED BY DEFAULT AS IDENTITY START WITH 6
PRIMARY KEY,
category_name VARCHAR2( 255 ) NOT NULL
);
-- products table
CREATE TABLE products
(
product_id NUMBER
GENERATED BY DEFAULT AS IDENTITY START WITH 289
PRIMARY KEY,
product_name VARCHAR2( 255 ) NOT NULL,
description VARCHAR2( 2000 ) ,
standard_cost NUMBER( 9, 2 ) ,
list_price NUMBER( 9, 2 ) ,
category_id NUMBER NOT NULL ,
CONSTRAINT fk_products_categories FOREIGN KEY( category_id ) REFERENCES product_categories( category_id ) ON DELETE CASCADE
);
-- customers
CREATE TABLE customers
(
customer_id NUMBER
GENERATED BY DEFAULT AS IDENTITY START WITH 320
PRIMARY KEY,
name VARCHAR2( 255 ) NOT NULL,
address VARCHAR2( 255 ) ,
website VARCHAR2( 255 ) ,
credit_limit NUMBER( 8, 2 )
);
-- contacts
CREATE TABLE contacts
(
contact_id NUMBER
GENERATED BY DEFAULT AS IDENTITY START WITH 320
PRIMARY KEY,
first_name VARCHAR2( 255 ) NOT NULL,
last_name VARCHAR2( 255 ) NOT NULL,
email VARCHAR2( 255 ) NOT NULL,
phone VARCHAR2( 20 ) ,
customer_id NUMBER ,
CONSTRAINT fk_contacts_customers FOREIGN KEY( customer_id ) REFERENCES customers( customer_id ) ON DELETE CASCADE
);
-- orders table
CREATE TABLE orders
(
order_id NUMBER
GENERATED BY DEFAULT AS IDENTITY START WITH 106
PRIMARY KEY,
customer_id NUMBER( 6, 0 ) NOT NULL,
status VARCHAR( 20 ) NOT NULL ,
salesman_id NUMBER( 6, 0 ) ,
order_date DATE NOT NULL ,
CONSTRAINT fk_orders_customers FOREIGN KEY( customer_id ) REFERENCES customers( customer_id ) ON DELETE CASCADE,
CONSTRAINT fk_orders_employees FOREIGN KEY( salesman_id ) REFERENCES employees( employee_id ) ON DELETE SET NULL
);
-- order items
CREATE TABLE order_items
(
order_id NUMBER( 12, 0 ) ,
item_id NUMBER( 12, 0 ) ,
product_id NUMBER( 12, 0 ) NOT NULL ,
quantity NUMBER( 8, 2 ) NOT NULL ,
unit_price NUMBER( 8, 2 ) NOT NULL ,
CONSTRAINT pk_order_items PRIMARY KEY( order_id, item_id ),
CONSTRAINT fk_order_items_products FOREIGN KEY( product_id ) REFERENCES products( product_id ) ON DELETE CASCADE,
CONSTRAINT fk_order_items_orders FOREIGN KEY( order_id ) REFERENCES orders( order_id ) ON DELETE CASCADE
);
-- inventories
CREATE TABLE inventories
(
product_id NUMBER( 12, 0 ) ,
warehouse_id NUMBER( 12, 0 ) ,
quantity NUMBER( 8, 0 ) NOT NULL,
CONSTRAINT pk_inventories PRIMARY KEY( product_id, warehouse_id ),
CONSTRAINT fk_inventories_products FOREIGN KEY( product_id ) REFERENCES products( product_id ) ON DELETE CASCADE,
CONSTRAINT fk_inventories_warehouses FOREIGN KEY( warehouse_id ) REFERENCES warehouses( warehouse_id ) ON DELETE CASCADE
);
在本教學中,我們介紹了Oracle範例資料庫並展示了如何下載它。現在,您應該準備好在Oracle資料庫伺服器中建立範例資料庫以供接下來的章節中練習。