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.

mysql ユニーク制約での注意事項

Posted at

mysqlのユニーク制約を使用する際にエラーになったので、注意事項をまとめてみた。

大文字や小文字が区別されない

ユニークキーになった値について、大文字小文字が区別されない
下記の3つが同じものと判断され、ユニーク制約違反となる
test
TEST
Test

3072bytes(utf8mb4で768文字)より長い文字列のカラムはユニーク制約を掛ける事ができない

ユニークキーには文字数制限がある 

例 
CREATE TABLE test_table (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    title VARCHAR(769) NOT NULL,
    unique(title)
) DEFAULT CHARSET=utf8mb4 ENGINE=InnoDB;

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?