EMPTY LINE
In ORACLE, an empty string is used to represent NULL. However, in almost everything else, an empty string is still a string, and therefore not NULL.
INTS
In your case, you are actually inserting STRINGS into the INT column. This results in an implicit CAST operation.
When your RDBMS converts the string '' to INT, it should get the value 0. Since 0 is not NULL, this is inserted.
A more correct test would be:
INSERT INTO `plekz`.`countries` (`Column1 ` , `Column2`) VALUES (66, NULL);
EDIT
Sorry, I only read your question half. You also ask how to stop. ''
Your first problem is that you insert STRINGS, and the table is defined as having INT fields. You can set restrictions on the data to be inserted, but these restrictions will apply the value after converting to INT. If you do not want the value 0 to be inserted as well, you cannot do anything for the table to prevent this scenario.
Your best bet is to decide why you insert rows first. You can use a stored procedure that accepts and validates strings before converting them to INT, and then inserting them. Or, even better, you can do checks in your client application.
The technically available option is to create CHAR fields and then set a limit on the fields, preventing them from being added. '' I would highly recommend .
MatBailie
source share