コンテンツにスキップ

Mermaid ER図のサンプル

erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ ORDER_ITEM : contains
PRODUCT ||--o{ ORDER_ITEM : "ordered in"
erDiagram
"アプリ利用者CSV" ||--|{ "アプリ利用者" : import
"アプリ利用者" {
string id PK
string user_id "from CSV"
string name_kana "from CSV"
date birthday "from CSV"
int gender_cd "from CSV"
int zip "from CSV"
int town_cd "from CSV"
string address1 "from CSV"
string address2 "from CSV"
string jno "突合後に格納"
string[] candidate_jno "突合後に候補者を格納"
string id_hash "アプリアップロード用"
string state "突合結果: MATCH | UNMATCH"
string message "エラー内容"
}
erDiagram
A ||--|| B : "1対1"
C ||--o{ D : "1対0以上"
E ||--|{ F : "1対1以上"
G }o--o{ H : "0以上対0以上"
I }|--|{ J : "1以上対1以上"
  • || : 正確に1つ(1)
  • o| : 0または1つ(0..1)
  • }{ : 0以上(0..n)
  • |{ : 1以上(1..n)
erDiagram
USERS {
int id PK "主キー、自動採番"
string email UK "ユニーク制約"
string password "ハッシュ化"
datetime created_at "作成日時"
datetime updated_at "更新日時"
boolean is_active "アクティブフラグ"
}
POSTS {
int id PK
int user_id FK "外部キー"
string title "NOT NULL"
text content "本文"
string status "ENUM: draft, published, archived"
datetime published_at "NULL許可"
}
USERS ||--o{ POSTS : writes
erDiagram
CUSTOMERS ||--o{ ORDERS : places
CUSTOMERS {
int id PK
string name
string email UK
string phone
datetime created_at
}
ORDERS ||--|{ ORDER_ITEMS : contains
ORDERS {
int id PK
int customer_id FK
datetime order_date
decimal total_amount
string status
string shipping_address
}
PRODUCTS ||--o{ ORDER_ITEMS : "ordered in"
PRODUCTS {
int id PK
string name
string sku UK
decimal price
int stock_quantity
boolean is_active
}
ORDER_ITEMS {
int id PK
int order_id FK
int product_id FK
int quantity
decimal unit_price
decimal subtotal
}
CATEGORIES ||--o{ PRODUCTS : categorizes
CATEGORIES {
int id PK
string name
int parent_id FK "自己参照"
int sort_order
}
erDiagram
AUTHORS ||--o{ ARTICLES : writes
AUTHORS ||--o{ COMMENTS : posts
AUTHORS {
string id PK "UUID"
string username UK
string email UK
string bio
string avatar_url
datetime joined_at
}
ARTICLES ||--o{ COMMENTS : receives
ARTICLES ||--o{ ARTICLE_TAGS : tagged
ARTICLES {
string id PK "UUID"
string author_id FK
string title
string slug UK
text content "Markdown"
string status "draft | published"
datetime published_at
int view_count
}
TAGS ||--o{ ARTICLE_TAGS : applied
TAGS {
int id PK
string name UK
string slug UK
int usage_count
}
ARTICLE_TAGS {
string article_id FK
int tag_id FK
}
COMMENTS {
string id PK
string article_id FK
string author_id FK
text content
datetime posted_at
boolean is_approved
}
erDiagram
ORGANIZATIONS ||--o{ USERS : employs
ORGANIZATIONS ||--o{ PROJECTS : owns
ORGANIZATIONS {
string id PK
string name
string slug UK
string plan "free | starter | pro"
datetime trial_ends_at
boolean is_active
}
USERS ||--o{ USER_ROLES : has
USERS ||--o{ ACTIVITIES : performs
USERS {
string id PK
string org_id FK
string email UK
string name
string avatar_url
datetime last_login_at
boolean is_active
}
ROLES ||--o{ USER_ROLES : assigned
ROLES {
int id PK
string name UK
string permissions "JSON配列"
}
USER_ROLES {
string user_id FK
int role_id FK
datetime assigned_at
}
PROJECTS ||--o{ TASKS : contains
PROJECTS ||--o{ PROJECT_MEMBERS : includes
PROJECTS {
string id PK
string org_id FK
string name
text description
date start_date
date end_date
string status
}
USERS ||--o{ PROJECT_MEMBERS : participates
PROJECT_MEMBERS {
string project_id FK
string user_id FK
string role "owner | admin | member"
}
TASKS ||--o{ ACTIVITIES : tracked
TASKS {
string id PK
string project_id FK
string assignee_id FK
string title
text description
string priority "low | medium | high"
string status "todo | in_progress | done"
datetime due_date
}
ACTIVITIES {
string id PK
string user_id FK
string task_id FK
string action
json details
datetime created_at
}
erDiagram
VEHICLES {
int id PK
string type "car | truck | motorcycle"
string manufacturer
string model
int year
}
CARS {
int vehicle_id FK
int door_count
string fuel_type
boolean has_sunroof
}
TRUCKS {
int vehicle_id FK
decimal cargo_capacity
int axle_count
boolean has_trailer_hitch
}
MOTORCYCLES {
int vehicle_id FK
int engine_cc
string type "sport | cruiser | touring"
}
VEHICLES ||--o| CARS : "is a"
VEHICLES ||--o| TRUCKS : "is a"
VEHICLES ||--o| MOTORCYCLES : "is a"

多対多の関係(中間テーブル)

Section titled “多対多の関係(中間テーブル)”
erDiagram
STUDENTS }o--o{ COURSES : enrolls
STUDENTS ||--o{ ENROLLMENTS : has
COURSES ||--o{ ENROLLMENTS : includes
STUDENTS {
int id PK
string student_number UK
string name
date enrollment_date
}
COURSES {
int id PK
string course_code UK
string name
int credits
string semester
}
ENROLLMENTS {
int student_id FK
int course_id FK
date enrolled_at
string grade
string status "active | dropped | completed"
}
erDiagram
"顧客マスタ" ||--o{ "注文" : "発注する"
"注文" ||--|{ "注文明細" : "含む"
"商品マスタ" ||--o{ "注文明細" : "注文される"
"顧客マスタ" {
int 顧客ID PK
string 顧客名
string メールアドレス UK
string 電話番号
datetime 登録日時
}
"商品マスタ" {
int 商品ID PK
string 商品名
string SKU UK
decimal 単価
int 在庫数
}
  1. 命名規則

    • テーブル名:複数形または単数形で統一
    • カラム名:snake_case または camelCase で統一
    • 主キー:id または テーブル名_id
  2. 関係性の明確化

    • 外部キーには FK を明記
    • 関係の種類(1対1、1対多など)を正確に表現
  3. コメントの活用

    • 各フィールドの用途をコメントで説明
    • ビジネスルールや制約を記載
  4. 視覚的な整理

    • 関連するエンティティは近くに配置
    • 読みやすさを重視した配置