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.

 

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.