Skip to content

Instantly share code, notes, and snippets.

@yuba
Last active October 24, 2017 10:29
Show Gist options
  • Save yuba/a186db3a2514023b4668 to your computer and use it in GitHub Desktop.
Save yuba/a186db3a2514023b4668 to your computer and use it in GitHub Desktop.
論理削除と一意性制約を両立させる方法・DB製品別 ref: http://qiita.com/yuba/items/70165875cfe02b03513d
CREATE UNIQUE INDEX mail_is_unique ON users (mail)
WHERE status = 0;
CREATE TABLE users (
id INT NOT NULL PRIMARY KEY,
mail VARCHAR NOT NULL,
status INT CHECK (status = 0),
CONSTRAINT mail_is_unique UNIQUE (mail, status)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment