Jump to content

More characters than specified in VARCHAR()?


echo_loser

Recommended Posts

If say, you were to set a table field to VARCHAR(5), and the user were to enter a string that is 6 characters long, how would MySQL react? Would it store the first 5 characters and ignore the last 6th character?

 

In the case that there is NO server side checking of course. I did keyword searches on Google with no luck to my question being answered.

 

There is a setting in the mySQL configuration file that affect this. It will either truncate to the defined (maximum) length and issue a warning;  OR it will raise an error (and not insert the data at all).

 

See the mySql manual

 

If strict SQL mode is not enabled and you assign a value to a CHAR or VARCHAR column that exceeds the column's maximum length, the value is truncated to fit and a warning is generated. For truncation of nonspace characters, you can cause an error to occur (rather than a warning) and suppress insertion of the value by using strict SQL mode. See Section 5.1.6, “Server SQL Modes”.

 

[EDIT]

It is good to be aware of these things, since the setting may be different between your development platform and the production server; which could cause errors to start occurring when moving from one server to the other.

[/EDIT]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.