What is the best column type for URL?

What is the best column type for URL field for SQL Server?

Type: VARCHAR or NVARCHAR?

Length ?

A similar question for MySQL .

+36
url sql-server
Jul 21 '09 at 15:24
source share
4 answers

If you are ready to always encode URLs before saving them (the example Google got was δΈ­ .doc URL encoding for% E4% B8% AD.doc), then you are safe with varchar. If you want non-ASCII characters in your URLs to remain readable in the database, I would recommend nvarchar. If you do not want to be caught, go to nvarchar.

Since IE (the most restrictive of the major browsers) does not support URLs longer than 2083 characters, (besides any considerations that may occur when indexing or line length), you can cover most of the useful scripts with nvarchar (2083).

+42
Jul 21 '09 at 15:34
source share

Will you store multilingual URLs? If so, use nvarchar , otherwise use varchar .

Edit: Regarding length, since IE restricts the URL to 2083 characters , you can use this as the maximum length of your field. In such cases, you want to use the lower common denominator, since your URLs should be used in all browsers. In fact, this is a practical cap on the field, which, most likely, will never contain data, will be anywhere, even within IE.

+10
Jul 21 '09 at 15:27
source share

For something like this, I am always mistaken on the side of caution and use nvarchar.

+3
Jul 21 '09 at 15:29
source share

For SQL Server, you'll want to use NVARCHAR, which I would think of, as there are plans (if not actions already) for non-Roman characters in the URLs. Currently, I see no problems in the extra storage requirements of NVARCHAR over VARCHAR.

+2
Jul 21 '09 at 15:29
source share



All Articles