I have a table with NOT NULL
fields and they end up empty.
What is the difference between a NULL
(allows null values) and NOT NULL
with an empty string ( ''
) inside?
I have a table with NOT NULL
fields and they end up empty.
What is the difference between a NULL
(allows null values) and NOT NULL
with an empty string ( ''
) inside?
You can not answer this question abstractly, because this has nothing to do with performance. Performance will be given if everything is done right within the needs. If you need one of them and not the other, it does not matter the performance.
There may be different performance by circumstances. The question should be semantic.
Some people say that you never need a NULL, but this fire and fire can give you performance problems because it implies over-normalizing and requiring complex operations to get the data the way you need it.
NULL
means no value, and blank means that it has an empty value, it's different things.
The difference is that a NULL
field can be null, ie no value is required. And a NOT NULL
field needs some value in the column, either a string.Empty
or a ""
.
I think that if you have a NOT NULL
field and you enter an empty string
fault, something is wrong with your architecture, because it's not worth having a NOT NULL
field if at some point you'll enter an empty value there inside. In that case, it would be best to turn this field into NULL
.
When you enter an empty value in some column in the database that accepts NULL
, whether this value is string.Empty
or ""
, it understands that this is an empty value, that is, it has a value there, however with nothing inside. In this case, you are taking up less of the bank space to store an empty value.
In order for the bank to continue showing NULL
and stay NULL
definitely, you enter a NULL
value that the bank understands. Something like:
command.Parameters.AddWithValue("@paymentDate", item.Renavam ?? (object)DBNull.Value);
That is, if the item.Renavam
is null, enter a value null
for the bank, which is DBNull.Value
. This way, your column will still remain as NULL
.