I think the field type should be string of variable length (VARCHAR), but what length should I use?
To clarify: I want to pick a size that would be able to store average URL, and don't really care about maximum possible.
I think the field type should be string of variable length (VARCHAR), but what length should I use?
To clarify: I want to pick a size that would be able to store average URL, and don't really care about maximum possible.
For I.E. the limit is 2,083 Characters
It appears that most other browsers don't have such limit, but if the URLs are supposed to be compatiable with all browsers I would suggest 2083 characters.
It depends of the URLs itself.
If you work with really long URLs like http://dsddsadashf.fsdfs.fd/fsdfsdfs/dfsdfsdfdsf/ssssdfsdfsd/sdfsdfsdfsd?fsdfsdfsdf=fdfsfsdfs&fsdfsdfsdfsdfs;jsessionid=sdasdsadasdasdfsdvhbdkvhjkdvhsk the you might consider CLOB field ;)
Size to fit the allowed length of a GET request. say 2048 (thats IE's max) http://www.boutell.com/newfaq/misc/urllength.html
On a side note, if any of these URLs are javascript bookmarklets;
javascript:var foo='bar';...alert('Hello World');
There is a limit of 508 characters in IE for the user, if they try to add this to their favorites.
Looks like you need a length of at least 190,000 if you want to support all modern browsers. Click here for details.
However, I think you would be fine with 2000. If a customer puts in a longer URL than that, you can blame them for the mistake and they will actually feel guilty about having done it. :)
While browsers support URLs with thousands of characters, that is rare, and you said yourself that you want to be able to store an average URL. The length of your field would depend on what you expect to be average. Are you primarily going to be storing "home pages" (as in user profiles)? Or would it be URLs that deep link to content on a site with long paths and/or query strings -- basically any URL?
If it's the latter (any URL), then go with the 2083 number mentioned in the answers to this question. Keep in mind that there is a maximum row size in SQL Server of roughly 8000 bytes, though. If this is the same table as a bunch of other information (again, such as user profiles), you may hit that limit.
For my own projects, there is typically some more context around what URLs will be stored. I typically come up with a list of potential URLs and decide on a length that would accomodate all of those, and then double it. I typically end up with a field length of 300 or 500 for URLs, and I don't remember ever having a problem.
you should use text as varchar could be only 255 chars long. text could be 65536 chars long.