6

空白だけで2つの文字列を入力した場合。このエラーメッセージが表示されます:

エラー1062:キー'PRIMARY'のエントリ''が重複しています

「自動トリム」をオフにするにはどうすればよいですか?

私はこれCharset: uft8-uft8_binとこのデータ型を使用しています:Varchar

4

1 に答える 1

10

SQL 92のドキュメントによると、2 つの文字列を比較する場合、最初に最も短い文字列にスペースを埋め込むことで長さが等しくなります。

ドキュメント内を検索し8.2 <comparison predicate>ます。

If the length in characters of X is not equal to the length
in characters of Y, then the shorter string is effectively
replaced, for the purposes of comparison, with a copy of
itself that has been extended to the length of the longer
string by concatenation on the right of one or more pad char-
acters, where the pad character is chosen based on CS. If
CS has the NO PAD attribute, then the pad character is an
implementation-dependent character different from any char-
acter in the character set of X and Y that collates less
than any string under CS. Otherwise, the pad character is a
<space>.

つまり、言い換えれば。入力したスペースの量で値を保存することではなく、重複する主キーをチェックするために行う比較です。したがって、スペースの量が異なる2つの文字列を主キーとして機能させることはできません

于 2013-02-05T09:04:37.567 に答える