Hi,
I'm not sure why you need to have this in sync? Also you have to consider that if this is a primary key on a table that any other tables using these referential identifiers will also need to be modified.
To answer your question below you can always drop the field and recreate it as follows:
Code:
SET INSERT_ID=1;
ALTER TABLE table_name DROP COLUMN id;
ALTER TABLE table_name ADD COLUMN id INT UNSIGNED AUTO_INCREMENT
PRIMARY KEY FIRST;
I do remember seeing some code once to get the sequence number of a row in the table and this could be used to update the table too.
The result of these commands can be seen next:
Code:
mysql> select * from test2;
+------+-------+-------+
| id | name | count |
+------+-------+-------+
| 1 | Mike | 0 |
| 2 | Duke | 2 |
| 3 | Smith | 1 |
| 4 | Dave | 6 |
| 6 | Rozie | 8 |
| 7 | Romeo | 0 |
| 8 | Khan | 1 |
+------+-------+-------+
7 rows in set (0.01 sec)
mysql> set insert_id = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> alter table test2 drop column id;
Query OK, 7 rows affected (0.06 sec)
Records: 7 Duplicates: 0 Warnings: 0
mysql> alter table test2 add column id int unsigned auto_increment primary key first;
Query OK, 7 rows affected (0.03 sec)
Records: 7 Duplicates: 0 Warnings: 0
mysql> select * from test2;
+----+-------+-------+
| id | name | count |
+----+-------+-------+
| 1 | Mike | 0 |
| 2 | Duke | 2 |
| 3 | Smith | 1 |
| 4 | Dave | 6 |
| 5 | Rozie | 8 |
| 6 | Romeo | 0 |
| 7 | Khan | 1 |
+----+-------+-------+
7 rows in set (0.00 sec)