Jump to content

Creating a new Column with a random INT


nipponese

Recommended Posts

Hi everyone,

 

I am wondering, how can I create a column with a unique auto-generated random integer in each row.

 

Obviously, something like this won't work:

ALTER TABLE contact ADD COLUMN invoice_id INT(SELECT FLOOR(1000 + (RAND() * 9000)));

 

But that's the idea...

 

Link to comment
https://forums.phpfreaks.com/topic/99230-creating-a-new-column-with-a-random-int/
Share on other sites

Hi everyone,

 

I am wondering, how can I create a column with a unique auto-generated random integer in each row.

 

Obviously, something like this won't work:

ALTER TABLE contact ADD COLUMN invoice_id INT(SELECT FLOOR(1000 + (RAND() * 9000)));

 

But that's the idea...

 

 

use a timestamp column for invoice id and default it to current_timestamp. You can convert it to string when using in php or whatever language you user.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.