0
1

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 3 years have passed since last update.

データベース、SQL・MySQLの基礎(命名規約)

Posted at

命名規約

1.全般

大文字を利用しない

テーブル名、カラム名ともに⼤⽂字を利⽤しないこと。(DBにより⼤⽂字⼩⽂字を区別するもの、しないものがあるため、⼩⽂字で統⼀を図る)

・悪い例
DOCUMENTS、Documents

・良い例
documents

複数単語の連携はスネークケース

テーブル名、カラム名ともに複数単語からなる場合は、全て⼩⽂字でスネークケースを⽤いること。(キャメルケース、キャメルバックはNG)

・悪い例
tableName、TableName、tablename

・良い例
table_name

英語表記を使い、略名は利用しない

使⽤⽬的を考慮し、わかりやすい名前をつける。
名前は英単語を基本とする。⽇本語(漢字、ひらがな等)、ローマ字、数字は使わない。
共通認識が取れていない略名は使わない。

・悪い例
start_dt、maker_cd

・良い例
start_date、maker_code

2.テーブル編

基本系 は 〜s(複数形)

・悪い例
document、category

・良い例
documents、categories

〜s(複数形) + "_" + 〜s(複数形)

・悪い例
userscategories、user_categories

・良い例
users_categories

3.カラム編

カラムは単数形を⽤いること。

name
age
is_working

また、以下のカラムは必須

id(主キー)
created_date(登録日時)
updated_date(更新日時)

他テーブルの主キーとジョイン(連結)するカラムは テーブル名(単数系)_id

テーブル名:users ⇨ カラム名:user_id
テーブル名:messages ⇨ カラム名:message_id

<前回の記事>
・データベース、SQL・MySQLの基礎(カラムの別名取得~シーケンス番号)
https://qiita.com/TaikiTkwkbysh/items/6bd3b6e873f33fbd898e

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?