Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why cant i set varchar to be 1000 in length

Tags:

mysql

if this matters, i also set it unique

The max I've managed to set for varchar is 745 (it's set to unique also).

like image 602
AleGore Avatar asked Mar 04 '10 17:03

AleGore


People also ask

Is there a limit on VARCHAR Max?

varchar [ ( n | max ) ] Use n to define the string size in bytes and can be a value from 1 through 8,000, or use max to indicate a column constraint size up to a maximum storage of 2^31-1 bytes (2 GB).

Is VARCHAR max 255?

VARCHAR(255) stores 255 characters, which may be more than 255 bytes.

What is the default length of VARCHAR?

VARCHAR is a variable-length character data type. The default length is 80, and the maximum length is 65000 octets. For string values longer than 65000, use Long Data Types. Values can include trailing spaces.

Do I have to specify length with VARCHAR?

Always specify a length to any text-based datatype such as NVARCHAR or VARCHAR . Don't over-use the MAX specification either as the resulting column then can't be indexed and comes with performance baggage.


1 Answers

Depends what version of MySQL you are running, before 5.0.3 there was a 255 character limit for varchar:

Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions.

From: http://dev.mysql.com/doc/refman/5.0/en/char.html

like image 154
Cody Caughlan Avatar answered Sep 30 '22 21:09

Cody Caughlan