I have to store a url inside a MySQL table. What is the best practice for determining a area which will hold a URL by having an undetermined length?

  1. Cheapest common denominator max URL length among popular browsers: 2,083 (Ie)

  2. http://dev.mysql.com/doc/refman/5./en/char.html
    Values in VARCHAR posts are variable-length strings. The space could be specified like a value from to 255 before MySQL 5..3, and to 65,535 in five..3 and then versions. The effective maximum period of a VARCHAR in MySQL 5..3 and then is susceptible to the utmost row size (65,535 bytes, that is shared among all posts) and also the character set used.

  3. So ...
    < MySQL 5..3 use TEXT
    >= MySQL 5..3 use VARCHAR(2083)

VARCHAR(512) (or similar) ought to be sufficient. However, because you don't fully realize the utmost entire Web addresses under consideration, I would go direct to TEXT. The risk with this particular is obviously lack of efficiency because of CLOBs being far reduced than the usual simple string datatype like VARCHAR.

varchar(max) for SQLServer2005

varchar(65535) for MySQL 5..3 and then

This can allocate storage as need and should not affect performance.

Most browsers enables you to put large levels of data inside a URL and therefore plenty of things finish up creating large Web addresses so if you're speaking about anything further than the domain a part of a URL you will have to make use of a TEXT column because the VARCHAR/CHAR are limited.

I'm not sure about other browsers, but IE7 includes a 2083 character limit for HTTP GET procedures. Unless of course every other browsers have lower limits, I do not understand why you'd need anymore figures than 2083.

Most web servers possess a URL length limit (and that's why there's a mistake code for "URI too lengthy"), meaning there's an operating upper size. Discover the default length limit which are more popular web servers, and employ the biggest of these because the field's maximum size it ought to be ample.