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.

Accessで長いテキストに重複無しインデックス(ユニーク)設定した場合のインサートに注意

Last updated at Posted at 2022-08-22

今後のAccessのアップデートで挙動が変わるかもしれません。
ここに書いた内容と同じ挙動になるかどうか、使う環境(バージョン)で動作確認した方がよいです。

先頭255文字で重複判定される

例えば下記のようなテーブルを用意…
image.png

下記SQLのように256文字インサート。

INSERT INTO tester ( long_str )
VALUES ('256文字だよあああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ0');

次、下記SQLのように 末尾を1文字だけ変えた256文字の値 をインサートしようとすると…

INSERT INTO tester ( long_str )
VALUES ('256文字だよあああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ1');

ユニークカラムに対する重複例外になる。
image.png

また、 末尾1文字だけ削って255文字 の値でも同様の重複例外になる。

INSERT INTO tester ( long_str )
VALUES ('256文字だよあああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ');

さらに末尾1文字だけ削って254文字 の値ならインサート できる

INSERT INTO tester ( long_str )
VALUES ('256文字だよあああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ');

まとめ

『長いテキスト』に、重複無しインデックス(ユニーク)を設定した場合…
先頭255文字 まで一致しているレコードが既にあるとインサートできない。

「重複無しインデックス設定しているから、文字列全体を見て重複チェックしている だろう
と思っていると思わぬバグになるので注意。

バージョン

Windows 10 Pro 21H2 OSビルド 19044.1889
Microsoft Access for Microsoft 365 MSO (バージョン 2207 ビルド 16.0.15427.20166) 32 ビット

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?