Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Workbench TEXT() Column Parameter

Tags:

mysql

I dont usually use MySQL workbench, I am trying to create a table with a text column by choosing TEXT(), however I am not sure what value I should put in between the '()'. If I leave it blank it gives me the error:

The given data type TEXT() contains errors and cannot be accepted. The previous value is kept instead.

I can put a number inside the parentheses but I wanted to know how it affects the column.

I could not find any answers online. I know how it affects things such as DATETIME() but not this data type.

like image 373
user126865 Avatar asked Jul 23 '17 21:07

user126865


People also ask

How do I create a datatype for TEXT in MySQL?

The actual TEXT column type is of four types-TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT. The four TEXT types are very similar to each other; the only difference is the maximum amount of data each can store. The smallest TEXT type, TINYTEXT shares the same character length as VARCHAR.

What is ZF in MySQL WorkBench?

ZF is for Zero Filled. Suppose, we have declared int(3) and you want to store 21, then zero filled would output the result 021.

How do I add a value to a column in MySQL WorkBench?

Double-click the first entry in one of your columns and type the data to be added. After entering the necessary data, hit Enter on your keyboard. Double-click under that newly created row and create another. Once you add all of your data, click Apply to execute the SQL Script.


1 Answers

In TEXT(M) M is an optional length. From the docs:

An optional length M can be given for this type. If this is done, MySQL creates the column as the smallest TEXT type large enough to hold values M characters long.

So you can use it to specify the maximum number of characters you anticipate for the field.

If you omit the parens - just TEXT - it will default to 65,535. Otherwise, if you supply the parens and a value it will default to the appropriate text type (TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT).

See here for a comparison with VARCHAR. One difference is that you cannot directly index a TEXT field, it requires a prefix.

like image 136
Andy G Avatar answered Sep 20 '22 01:09

Andy G