void
void

Reputation: 1896

What is the most efficient way to store URL's in MySQL?

This is not actually a coding question, but I want to learn something.

I'm trying to save picture URL's for items in the database. At first, I made the *img_url* column of type TEXT, but turns out it cannot have a default value, which I need.

So I guess I will use something like VARCHAR(2000) , but on the other hand, most of the items will have the value "local" which is varchar(5). So what I want to learn is, will the table use memory space as if all the rows have strings of 2000 characters, even though most of the cells contain 5-char strings?

Upvotes: 0

Views: 166

Answers (2)

hexparrot
hexparrot

Reputation: 3417

Have a look at the MySQL documentation on Storage Requirements.

As you'll see, the cost of storing a value is not in the VARCHAR(length), but instead directly related to the data it is storing, with some overhead.

VARCHAR(M), VARBINARY(M) L + 1 bytes if column values require 0 – 255 bytes, L + 2 bytes if values may require more than 255 bytes

The value local, thus would take 6 bytes.

Upvotes: 1

searlea
searlea

Reputation: 8378

No. That's what the VAR in VARCHAR indicates.

See the documentation for VARCHAR, especially the table about storage usage.

Upvotes: 0

Related Questions