What is the best data type to store URLs?
I need to 开发者_开发技巧save file system paths for pictures in a database.
URLs are strings and will be of variable lenghts.
If your database system supports this, use VARCHAR.
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.
VARCHAR2(4000) is sufficient for your needs
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.
varchar
. Choose a suitable max length based on your domain knowledge.
精彩评论