LoginSignup
0
1

More than 3 years have passed since last update.

SQL Server の大雑把な値認識

Last updated at Posted at 2019-07-01

はじめに

SQL Server は、「照合順序」の設定で変えられますが、デフォルト設定での値認識がかなり大雑把です。
便利ではあるのですが、キー値の処理など厳密に値を管理する必要がある場合は注意が必要です。

値を同一とみなすパターン

以下、それぞれで、同じレコードが検索されます。
値を同一とみなすということは、主キー値の場合は、両方INSERTしようとすると一意制約違反になります。

大文字小文字を同一とみなす

select * from T1 where T1.ID = 'A123';
select * from T1 where T1.ID = 'a123';

全角半角を同一とみなす

select * from T1 where T1.ID = 'A123';
select * from T1 where T1.ID = 'A123';

平仮名と片仮名を同一とみなす

select * from T1 where T1.NAME = 'あいうえお';
select * from T1 where T1.NAME = 'アイウエオ';
select * from T1 where T1.NAME = 'アイウエオ';

参考サイト

おわりに

DBによって値の扱いが異なるので、思い込みで実装するのは危険ですね。

0
1
2

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
1