9

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.

1 Answer 1

11

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, I guess I was thinking about the data type wrong. I thought if we left it blank it would default to some value.
I've added a little more info to my answer.
Yes, you can index a text field, just you must use a prefix.
Thank you for the clarification. I've adjusted my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.