Welcome Guest, Not a member yet? Register   Sign In
Insert NULL
#7

(This post was last modified: 05-09-2020, 09:15 AM by Gary.)

If you're using the database in STRICT mode, if you have '' in a TINYINT field it'll likely complain. Of course, NULL won't have this problem if it's set as 'allowed' in the database config... but be aware that (if it's not explicitly allowed, but you're running in the default NON-STRICT mode), according to the documentation, it will be implicitly converted: to an empty string for string types, and the zero value for numeric, date and time types.

I believe NULL is probably stored as a single CHAR (byte), and under certain types of encoding as two bytes. Though, saying that, I can't see how it could be stored as a single byte in your TINYINT field without having to be two bytes.

0 will be one byte in your TINYINT field, and '' will be stored either as one byte (in the prefix byte) if it's stored in a VARCHAR field, or as the maximum field-length if a CHAR field (eg: in a CHAR field of length 10, '' will store it as ten empty CHARs (the CHAR type is a fixed-length field). So NULL can be better for some, but not all field types.

The other way you could try to do it, if you're running in the default NON-STRICT mode, is to simply let '' be 0 ('like new') and YES=1, NO=2. You could probably fiddle your code without too much effort to have this also work whilst in STRICT mode too (?).

Not sure that gives you an answer... though, there are a few things to think about. Wink
Reply


Messages In This Thread
Insert NULL - by Leo - 05-06-2020, 12:34 PM
RE: Insert NULL - by jreklund - 05-06-2020, 01:01 PM
RE: Insert NULL - by Leo - 05-07-2020, 01:12 AM
RE: Insert NULL - by jreklund - 05-07-2020, 11:23 AM
RE: Insert NULL - by Gary - 05-07-2020, 05:40 PM
RE: Insert NULL - by Leo - 05-08-2020, 10:07 PM
RE: Insert NULL - by Gary - 05-09-2020, 09:13 AM
RE: Insert NULL - by Leo - 05-09-2020, 03:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB