Reputation: 73918
What is the best data type to store URLs?
I need to save file system paths for pictures in a database.
Upvotes: 8
Views: 23021
Reputation: 25370
VARCHAR is quite enough.
CHAR should be used for storing fix length character strings. String values will be space/blank padded before stored on disk. If this type is used to store varibale length strings, it will waste a lot of disk space.
Upvotes: 5
Reputation: 6087
We tend to save them as urlencoded VARCHAR
s. (Since our URLs are coming to the database from a server, we encode them using PHP's urlencode
and then decode them when we retrieve them with urldecode
.) Don't think there's really much else that needs done - you could probably just store them as unencoded VARCHAR
s.
Upvotes: 3
Reputation: 499002
URLs are strings and will be of variable lenghts.
If your database system supports this, use VARCHAR.
Upvotes: 6
Reputation: 42125
varchar
. Choose a suitable max length based on your domain knowledge.
Upvotes: 2