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

15

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

  • What is the utility of the zero-length varchar column type?
asked by anonymous 21.03.2017 / 14:10

2 answers

14

According to the MYSQL manual :

  

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

    
21.03.2017 / 14:16
5

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

  • You need only 1 bit;
  • An unorthodox way of having boolean , with NULL / ' ' to false / true ;
  • Maintainability of a legacy system where values are no longer needed, but it is impracticable to make a DROP COLUMN , as it could lead to a series of problems due to its lack;

This is not standard, but MySQL allows. In the SQL SERVER for example:

  

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

    
21.03.2017 / 15:13