What is the use of the varchar(0) column type?

Asked

Viewed 286 times

15

I saw a question about column length of type Varchar and went to consult a book I have and came across the following statement: The maximum length should be a number between 0 to 255.

  • What is the usefulness of the zero-length varchar column type?

2 answers

13


According to the manual of MYSQL:

Mysql allows you to create a type column VARCHAR(0). That is useful especially when you need to be compatible with systems which depend on the existence of the column, but which do not use its value. VARCHAR(0) It’s also quite nice when you need one column that can have only two values: A column that is defined as VARCHAR(0) NULL occupies only one bit and can have only the values NULL and ' ' (empty string).

  • In addition to old system, what is the use of having a column with NULL values?

  • @Laerte I did not understand the question. This question Bigown answers your question? :)

  • My question is more related to that question right here, I wonder what is the use of having a column that accepts ONLY null and not those that accept null and normal values.

  • 3

    I found, it was not specifically about zero column, but the situation is analogous: A varchar(0) with NULL or does not behave the same column BIT: http://answall.com/questions/108842/70 - And only take advantage of space if you have more than one.

5

Just like the @Marconi already mentioned as per the documentation, you can see as follows:

  • You need only 1 bit;
  • An unorthodox way to have a boolean, with NULL/' ' for false/true;
  • Maintainability of a legacy system where values are no longer required, but it is impossible to perform a DROP COLUMN, because it could lead to a number of problems due to its lack;

This is not standard, but the MySQL permits. No SQL SERVER for example:

char [ ( n ) ] Non-unicode character string data fixed length. n defines the length of the string and should be a value of 1 to 8,000. The storage size is n bytes. The synonym ISO for char is characters.

  • 2

    Beautiful magnification +1.

Browser other questions tagged

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