List:General Discussion« Previous MessageNext Message »
From:Michael Dykman Date:April 28 2009 5:13am
Subject:Re: How to generate unique primary key in MySQL?
View as plain text  
Ok, I will ask the obvious question: why do you refuse to use
auto_increment?  If this was Oracle or Postgresql, of course we would
use sequences, but that isn't available in MySQL.  Personally, I would
not go to Rome to order the sushi.

However, there is the function uuid() which can be used ie.

SELECT uuid();

and produces a guaranteed unique 36 character sitrng, but this might
not be very efficient in joins as your dataset grows.

 - michael dykman

On Tue, Apr 28, 2009 at 12:59 AM, yuan edit <edit.yuan@stripped> wrote:
> I have a shopping cart table like this:
>
> CREATE TABLE shopping_cart(
> id VARCHAR(20) NOT NULL,
> product_id INT NOT NULL,
> product_quantity INT NOT NULL,
> ...
> ...
> user_id INT NOT NULL,
> current_timestamp TIMESTAMP,
> primary key (id)
> );
>
> I will not use auto_increment
>
> Is there other way to  generate unique primary key in MySQL?
>
> Thank you
>



-- 
 - michael dykman
 - mdykman@stripped

 - All models are wrong.  Some models are useful.
Thread
How to generate unique primary key in MySQL?yuan edit28 Apr
  • Re: How to generate unique primary key in MySQL?yuan edit28 Apr
  • Re: How to generate unique primary key in MySQL?Michael Dykman28 Apr
  • Re: How to generate unique primary key in MySQL?Jim Lyons28 Apr
Re: How to generate unique primary key in MySQL?Michael Dykman28 Apr