0

In my Mysql DB I have a field which is used to store user-inputted text, and therefore set as Text and not varchar.

A user can input a maximum of 3000 characters which is then saved into the Text field.

So, should I give the Text field an length of 3000 in Mysql? Since thats the maximum characters a user can submit. More or less like length with varchar works.

Thanks in advance,

user2722667
  • 8,195
  • 14
  • 52
  • 100

1 Answers1

0

A MySQL text field can store a maximum of 65535 characters (using single-byte characters).

You don't need to specify a text field's length like you do for varchar.

user3792628
  • 168
  • 3
  • 10
  • But in order to add a Index key to the text field. Do I have to set a length first? Coz right now I cant add a index key to the text field, or that might be just coz it is a text field. – user2722667 Jul 01 '14 at 09:53
  • TEXT columns can be indexed but a prefix length must be given. Example: `CREATE UNIQUE INDEX index_name ON myfield (key(10));` This example indexes just the first 10 characters. – user3792628 Jul 01 '14 at 22:55