Reputation: 1069
I am going to store URLs inside of my database and I just had a simple question. Do URLs have to be a certain data type?
Upvotes: 0
Views: 2684
Reputation: 18853
Simply put the data type should be VARCHAR
URLs can contain any number of characters, and can be any length (within reason on the smaller end). A CHAR
field can only contain the number of characters that is set in the table definition. A VariableCharacter (VARCHAR
) field can contain a variable number of characters. So since not all URL's are of equal length you need the variability. You could make an argument to use a TEXT
field if you needed to store really long URLs; however, for most use cases VARCHAR
will suffice.
Upvotes: 9
Reputation: 1
An url has special, numerically and normal chars. Therefor you should use the type "VARCHAR" in MySql.
Upvotes: 0