views:

149

answers:

2

Hi,

Is it possible to have two and more primary/automatic-adding unique IDs per one table in MySQL? For example:

Primary Key (INT,11);shop_id;invoice_id

1;200;2001
1;201;2011
2;200;2002
2;201;2012

Is it possible to set this to MySQL table ? -> So there are more primary keys for some other value in the table.. ?

I am looking for more auto-increments in one table.

A: 

You can only have a single AUTO_INCREMENT column per table in MySQL. You can only have a single PRIMARY key in a table in MySQL, but it can be a composite key and consist of more than one column.

But from the example you gave, it looks like you're asking for something different. Can you clarify?

Joe W.
+1  A: 

are you looking for AUTO_INCREMENT on a secondary column in a multiple-column index? you can do this for MyISAM tables.

ax
I know I could take a peek to documentation but what is MyISAM table? can i convert my table to it?
Skuta
MyISAM [1] is MySQL's default storage engine (non-transaction-safe). If your table isn't MyISAM yet (SHOW CREATE TABLE t, look for "ENGINE=..." ), you can convert to it with ALTER TABLE t ENGINE = MYISAM;[1] http://dev.mysql.com/doc/refman/5.1/en/myisam-storage-engine.html
ax