- (F table.column) は、table.column を指す外部キーを意味します。
- (P) は主キーを意味します
- (U) は一意のキーを意味します
ここにいくつかのテーブルとサンプルデータがあります...
addresses
id unsigned int(P)
line1 varchar(50)
line2 varchar(50) // Allow NULL
city_id unsigned int(F cities.id)
zip varchar(6) // 5 digits for US and MX, 6 characters (X9X9X9) for CA
zip4 char(4) // Allow NULL
+----+-----------------+-------+---------+--------+------+
| id | line1 | line2 | city_id | zip | zip4 |
+----+-----------------+-------+---------+--------+------+
| 1 | 123 Main Street | Apt A | 17 | 92101 | 1234 |
| 2 | 345 East Street | NULL | 25 | T1X0L3 | NULL |
| .. | ............... | ..... | ....... | ...... | .... |
+----+-----------------+-------+---------+--------+------+
cities
id unsigned int(P)
state_id unsigned int(F states.id)
name varchar(50)
...
+----+----------+-----------+-----+
| id | state_id | name | ... |
+----+----------+-----------+-----+
| .. | ........ | ......... | ... |
| 17 | 130 | San Diego | ... |
| .. | ........ | ......... | ... |
| 25 | 14 | Calgary | ... |
| .. | ........ | ......... | ... |
+----+----------+-----------+-----+
ISO 3166-1を参照
countries
id char(2)(P)
iso3 char(3)(U)
iso_num char(3)(U)
name varchar(45)(U)
+----+------+---------+---------------+
| id | iso3 | iso_num | name |
+----+------+---------+---------------+
| .. | .... | ....... | ............. |
| CA | CAN | 124 | Canada |
| .. | .... | ....... | ............. |
| MX | MEX | 484 | Mexico |
| .. | .... | ....... | ............. |
| US | USA | 840 | United States |
| .. | .... | ....... | ............. |
+----+------+---------+---------------+
パスワードのハッシュについては、 PHP の crypt() 関数を参照してください。
customers
id unsigned int(P)
first_name varchar(50)
middle_name varchar(50) // Allow NULL
last_name varchar(50)
email varchar(255)
username varchar(32)
password varbinary(255) // hashed
...
+----+------------+-------------+-----------+----------------------------+-----------+----------+-----+
| id | first_name | middle_name | last_name | email | username | password | ... |
+----+------------+-------------+-----------+----------------------------+-----------+----------+-----+
| 1 | John | Quincy | Public | jqp@privacy.com | johnqball | xxxxxxxx | ... |
| 2 | Jane | NULL | Doe | ladyinred@chrisdeburgh.com | janeykins | xxxxxxxx | ... |
| .. | .......... | ........... | ......... | .......................... | ......... | ....... | ... |
+----+------------+-------------+-----------+----------------------------+-----------+----------+-----+
customers_addresses
id unsigned int(P)
customer_id unsigned int(F customers.id)
address_id unsigned int(F addresses.id)
orders
id unsigned int(P)
customer_id unsigned int(F customers.id)
bill_address_id unsigned int(F addresses.id)
ship_address_id unsigned int(F addresses.id)
created datetime
shipped datetime
...
+----+-------------+-----------------+-----------------+---------------------+---------------------+-----+
| id | customer_id | bill_address_id | ship_address_id | created | shipped | ... |
+----+-------------+-----------------+-----------------+---------------------+---------------------+-----+
| 1 | 1 | 1 | 1 | 2012-12-31 23:59:59 | 2013-01-01 00:00:00 | ... |
+----+-------------+-----------------+-----------------+---------------------+---------------------+-----+
orders_products
id unsigned int(P)
order_id unsigned int(F orders.id)
product_id unsigned int(F products.id)
quantity unsigned int
unit_price double
...
+----+----------+------------+----------+------------+-----+
| id | order_id | product_id | quantity | unit_price | ... |
+----+----------+------------+----------+------------+-----+
| 1 | 1 | 1 | 1 | 12.34 | ... |
| 2 | 1 | 2 | 13 | 1.78 | ... |
| .. | ........ | .......... | ........ | .......... | ... |
+----+----------+------------+----------+------------+-----+
products
id unsigned int(P)
name varchar(50)
price double
...
+----+----------+-------+-----+
| id | name | price | ... |
+----+----------+-------+-----+
| 1 | Widget 1 | 12.34 | ... |
| 2 | Widget 2 | 1.78 | ... |
| .. | ........ | ..... | ... |
+----+----------+-------+-----+
returns
id unsigned int(P)
order_product_id unsigned int(F orders_products.id)
quantity unsigned int
...
+----+------------------+----------+-----+
| id | order_product_id | quantity | ... |
+----+------------------+----------+-----+
| 1 | 1 | 1 | ... |
| .. | ................ | ........ | ... |
+----+------------------+----------+-----+
ISO 3166-2を参照
states
id unsigned int(P)
country_id char(2)(F countries.id)
code char(2) // AB, AL, NL, etc.
name varchar(50) // Alberta, Alabama, Nuevo Leon, etc.
...
+-----+------------+------+------------+-----+
| id | country_id | code | name | ... |
+-----+------------+------+------------+-----+
| ... | .......... | .... | .......... | ... |
| 14 | CA | AB | Alberta | ... |
| ... | .......... | .... | .......... | ... |
| 72 | MX | CH | Chiapas | ... |
| ... | .......... | .... | .......... | ... |
| 130 | US | CA | California | ... |
| ... | .......... | .... | .......... | ... |
+-----+------------+------+------------+-----+
返品、返金、および交換はすべて実際には返品です。お客様は製品を返品しています。それをどのように処理するかは、ビジネスルールによって異なります...