tags:

views:

68

answers:

6

Hi, what is the best data type to store Urls?.

I need save on database file system path for pictures.

thanks

+2  A: 

VARCHAR is quite enough.

Michael Pakhantsov
sorry, why not use char instead? thanks
GIbboK
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.
Michael Pakhantsov
thanks i understand now
GIbboK
+2  A: 

varchar. Choose a suitable max length based on your domain knowledge.

Neil Barnwell
sorry why varchar and not just char?
GIbboK
@GibboK: Because you would be wasting a lot of space using `char`. Unlike the fixed-size `char` data type, `varchar` does not store any blank characters when the full length of the field is not used.
Daniel Vassallo
Because char is fixed-length and you'd be wasting a lot of space.
Neil Barnwell
varchar because the db can trim unused space, unless all your URLs are going to be the same length.
Adam
+3  A: 

URLs are strings and will be of variable lenghts.

If your database system supports this, use VARCHAR.

Oded
+1  A: 

VARCHAR2(4000) is sufficient for your needs

The chicken in the kitchen
+2  A: 

We tend to save them as urlencoded VARCHARs. (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 VARCHARs.

Stephen
Thanks Stephen, may i ask you WHY it is useful encode URLS in database?
GIbboK
For security purposes
Neurofluxation