タグ

ブックマーク / qiita.com/mojatter (1)

  • 論理削除とユニークキー制約の両立 - Qiita

    概要 データベーステーブルの物理設計を行うとき、論理削除とユニークキー制約を両立させるための TIPS です。 基create table user ( id int not null, email varchar(40) not null, password_sha256 varchar(64) not null, removed int not null default 0, -- 論理削除カラム constraint pk primary key (id) ); -- 入会 insert into user (id, email, password_sha256) values (1, 'foo@example.com', '**dummy**'); -- ログイン removed = 0 select * from user where removed = 0 and ema

    論理削除とユニークキー制約の両立 - Qiita
    k-holy
    k-holy 2015/11/12
    論理削除に限らず何らかのフラグと一意性制約を組み合わせる場合に使えそう
  • 1