0

私は最も奇妙な問題を抱えています-私が走ったとき:

SELECT * FROM `words` WHERE `translation` = ''

私は得る:Showing rows 0 - 29 (6,925 total, Query took 0.0008 sec)

しかし、私が実行すると:

UPDATE `words` SET `translation`= NULL WHERE `translation`= ''

私は得る:0 row(s) affected. ( Query took 0.2200 sec )

なぜ行を更新したくないのですか?これは同じWHERE句です。

4

5 に答える 5

3

デフォルト値で、translationとして宣言されていますか?その場合、に設定しても効果はなく、MySQLは行が変更されていないことを正しく報告します。つまり、と同等のことを行っています。not null''NULLUPDATEUPDATE words SET translation = 'a' WHERE translation = 'a'

ただし、警告が表示されるはずです。MySQLコマンドラインクライアントは、次のような警告を報告します。

mysql> UPDATE words SET translation=NULL WHERE translation = '';
Query OK, 0 rows affected, 2 warnings (0.00 sec)
Rows matched: 2  Changed: 0  Warnings: 2

警告を表示するには、次のコマンドを使用しますshow warnings;

mysql> show warnings;
+---------+------+-------------------------------------+
| Level   | Code | Message                             |
+---------+------+-------------------------------------+
| Warning | 1048 | Column 'translation' cannot be null |
| Warning | 1048 | Column 'translation' cannot be null |
+---------+------+-------------------------------------+
于 2012-05-24T08:48:56.467 に答える
3

OK、これを試してください:

UPDATE words SET translation='$$$' WHERE translation = '';
UPDATE words SET translation=NULL WHERE translation = '$$$';

そして第二に; 多分列定義はNULL値を許可していませんか?テーブルのデザインを確認してください。

于 2012-05-24T08:50:02.287 に答える
0

翻訳はnullを許可すると思います、それがosの場合はこれを試してください

 UPDATE `words` SET `translation`= NULL WHERE `translation IS NULL.
于 2012-05-24T09:10:40.583 に答える
0

translation列を許可しないでくださいNULL。戻りますか

Error Code: 1048
Column 'translation` cannot be null

ステートメントを実行するとき?

于 2012-05-24T08:52:45.203 に答える
-1

IDなどの他の列を使用してみてください

update 'words' set 'translation'=null where id in (select id from 'words' where 'translation'=''

なぜこれが起こっているのか分かりません。

于 2012-05-24T08:45:15.887 に答える