tags:

views:

37

answers:

2

I have a table that contains thousands of URLs. Each URL will have a corresponding folder, so I was considering using mySQL to create a short and usable folder name for each existing URL and for new URLs as they are added to the table.

What I would like is to specify something like a field 5 chars long of chars a-z, and have mySQL autogenerate values for that field.

Can the mySQL engine do this natively, or would I have to do this in code?

A: 

Depending on whether you want to be able to easily determine the URL the folder name is associated with, you might find that using a UUID will provide you with a suitable way.

INSERT INTO t (`url`, `uuid`) VALUES('http://www.example.com/', UUID());

Other mechanisms along the same line include using MD5() and SHA1()

http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_uuid http://dev.mysql.com/doc/refman/5.0/en/other-functions.html

Note that these are going to be longer than 5 chars that you mentioned, though it's possible you'll need more than that to allow sufficient space.

ptomli
+1  A: 

Just use an auto-generated long/bigint ID and convert it after all from/to base 36 or 64.

BalusC
OMG Ponies