GibboK
GibboK

Reputation: 73918

Data Type for storing URLs

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

Answers (5)

Michael Pakhantsov
Michael Pakhantsov

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

Stephen
Stephen

Reputation: 6087

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.

Upvotes: 3

UltraCommit
UltraCommit

Reputation: 2276

VARCHAR2(4000) is sufficient for your needs

Upvotes: 4

Oded
Oded

Reputation: 499002

URLs are strings and will be of variable lenghts.

If your database system supports this, use VARCHAR.

Upvotes: 6

Neil Barnwell
Neil Barnwell

Reputation: 42125

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

Upvotes: 2

Related Questions