What is the use of declaring a column as Char(0)?

Asked

Viewed 40 times

1

I know that CHAR(0) is not defined in ANSI SQL, but in Mysql it is possible to define a column specifying this type of data.

What would be the use/usefulness of such a column?

1 answer

2


It is to keep the existing column in the template without occupying real data space.

Some applications may want to access a column that no longer makes sense to exist in DB or that it is not yet time to actually use it. So not to break the application you keep the existing column, which will be included in requests, including when you make a select * from she’ll be there, even without giving any real.

Mysql tends to be more permissive and I find this specific permissiveness good because it is useful in cases like this. It’s just not to abuse. Tends to be more useful when the database ends up working as a system API, which is not usually a good choice.

It is still possible to use to indicate the nullity of a value or not (and only this is indicated, nothing else). Because all columns are controlled with one bit, then it will take up the 1 bit space, which can change the row size or not depending on the composition of the other columns. You can see more about this at Bacco’s response on database nullity.

I have seen people using this to have a boolean data smaller than the existing one that occupies 1 byte, but it is abuse, and may have difficulties in the future because of this, I would not risk.

  • takes only one bit and can only take 2 values: NULL or '' (the empty string)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.