0

I would have expected this to fail, but instead it wipes the existing data and replaces it with an empty string. Is this correct behaviour? If it is, is there a work around to force an error instead

Eg

CREATE TABLE testtable 
    (columna VARCHAR(30) NOT NULL,
    columnb VARCHAR(2) NULL,
    columnc VARCHAR(10) NULL);

INSERT INTO testtable (columna, columnb, columnc)
VALUES ('first entry', '1', null),
    ('second entry', '2', null),
    ('third entry', '3', null);

INSERT INTO testtable (columna, columnb, columnc)
VALUES (null, '4', null);

This fails with error Error Code: 1048. Column 'columna' cannot be null which is what I would expect.

However,

UPDATE testtable
SET columna = null WHERE columnb = '2';

replaces contents of columna with an empty string

Select * from testtable;

first entry 1   
            2   
third entry 3   
4

1 に答える 1

0

これはSQLモードにかかっていることがわかりました。設定することにより

SET GLOBAL sql_mode = 'TRADITIONAL';

データベースは期待どおりに機能し、無効な値を拒否します。

于 2013-03-03T19:24:24.447 に答える