Page 1 of 1
Check next available index has auto-increment
Posted: Mon Oct 20, 2003 8:17 pm
by richie256
Hi everybody
In MySQL, in the index field, I just don't know how to check for the next available field to act has a auto-increment...
Thanks!
Posted: Mon Oct 20, 2003 8:21 pm
by markl999
Presuming there's reasons you don't want to use an actual auto-increment field you could just SELECT MAX(id) AS themax FROM foo and the next 'available' should be $themax+1
Posted: Mon Oct 20, 2003 8:26 pm
by richie256
Ha ok right.
I want to use this way because there is two table with the same index... A primary table and a secondary table... I want to do this way because I think it is easier to program!!
Thank you!
Posted: Tue Oct 21, 2003 2:51 am
by twigletmac
Two tables with identical primary keys sounds like it's going to give you headaches and in the long run keeping them in synch is probably not going to be very easy.
Mac
Posted: Tue Oct 21, 2003 11:30 am
by richie256
twigletmac wrote:Two tables with identical primary keys sounds like it's going to give you headaches and in the long run keeping them in synch is probably not going to be very easy.
I must do this way:
In the first table (primary) I have the primary key and different fields, and in the second table, I have two keys: same key as primary table with the language key to have descriptions in different languages.
So I must do this way to support different language. For exemple, if I wish to add a new language, it will be easy.
Posted: Tue Oct 21, 2003 12:32 pm
by jason
Table 1 is assumed to have the auto_incrementing field.
Table 1: INSERT INTO table (field) VALUES ('value');
Table 2: INSERT INTO other_table (primary_key, field) VALUES (LAST_INSERT_ID(), 'value');
So I must do this way to support different language. For exemple, if I wish to add a new language, it will be easy.
Actually, it would probably be easier to set a primary key of the Id and the language of the article. And make the language of the article (or whatever content it is) and ENUM. Then simply select on that.