Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best column type for URL?

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

Type: VARCHAR or NVARCHAR?

Length?

Similar question for MySQL.

like image 853
Adrian Godong Avatar asked Jul 21 '09 15:07

Adrian Godong


People also ask

What data type is image URL?

A Data URL is a string that starts with data: followed by the MIME type format. For example a PNG image has mime type image/png . This is followed by a comma and then by the actual data. Text is usually transferred in plain text, while binary data is usually base64 encoded.

Which data type allows storing URLs of websites or email address?

Since URLs are variable length strings the VARCHAR data type would seem the obvious choice.

Which is better VARCHAR or text in mysql?

In most circumstances, VARCHAR provides better performance, it's more flexible, and can be fully indexed. If you need to store longer strings, use MEDIUMTEXT or LONGTEXT, but be aware that very large amounts of data can be stored in columns of these types.


1 Answers

If you are prepared to always URL encode your URLs before you store them (an example turned up by Google was 中.doc URL encoding to %E4%B8%AD.doc) then you are safe sticking with varchar. If you want the non-ASCII characters in your URLs to remain readable in the database then I'd recommend nvarchar. If you don't want to be caught out, then go for nvarchar.

Since IE (the most restrictive of the mainstream browsers) doesn't support URLs longer than 2083 characters, then (apart from any considerations you might have on indexing or row length), you can cover most useful scenarios with nvarchar(2083).

like image 187
David M Avatar answered Oct 11 '22 09:10

David M