List:General Discussion« Previous MessageNext Message »
From:Jim Lyons Date:April 28 2009 10:53am
Subject:Re: How to generate unique primary key in MySQL?
View as plain text  
If you just don't want a primary key in your major data tables, then create
a table for the express purpose of generating primary keys that uses
auto_increment.  Something like:

create table myseq (x   serial;)


Each time you need a new key, get the next value from that table.  It would
be more like an Oracle sequence that an auto_increment.

On Mon, Apr 27, 2009 at 11:59 PM, 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
>



-- 
Jim Lyons
Web developer / Database administrator
http://www.weblyons.com

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