0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

データベースのカラム名を考える

Last updated at Posted at 2023-02-03

1 . はじめに

  • データベースのカラム名をある程度統一したルールで記述したい
  • フラグなのにTRUE/FALSE, ON/OFF以外のものがある時に正しく説明したい

2. 命名規則

  • 過去の経験や書籍などから自分なりに必要最低限のルールをまとめてみる

2.1. カラム名

  • 下記種類のカラムについては接尾辞を追加する
接尾辞 種類 文字数 使用用途 (例) 型 (例) 説明
Id ID 1~ ユーザーID ※任意 レコードを一意にに特定可能な項目
Code コード 2~ 商品コード VARCHAR 桁数ごとに意味を持つ項目
No 番号 1~ シーケンス番号、表示順 ※任意 順番を表す項目
Kbn 区分 1~ 商品区分 VARCHAR 複数の項目から値を紐づける項目
Flag フラグ 1 在庫区分 BIT 二者択一の項目(TRUE/FALSE, ON/OFF)
Num 1~ 在庫数 整数 特定のモノに関する数(数量、幅など)を表す項目
Date 日付 - 登録日付 DATE 年月日を表す項目
Dt 日時 - 更新日付 DATETIME 年月日時分秒を表す記録する項目
  • 上記以外の項目はドメインで名前、型を定義して管理する

2.2 WHOカラム

  • 各テーブルの最後に必ず下記カラムを追加する
    • 登録ユーザーID
    • 登録日時
    • 登録プログラムID
    • 更新ユーザーID
    • 更新プログラムID
    • 更新日時

3. 参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?