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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.