Last active
October 24, 2017 10:29
-
-
Save yuba/a186db3a2514023b4668 to your computer and use it in GitHub Desktop.
論理削除と一意性制約を両立させる方法・DB製品別 ref: http://qiita.com/yuba/items/70165875cfe02b03513d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE UNIQUE INDEX mail_is_unique ON users (mail) | |
WHERE status = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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