MySQL IDs question
#1

For each new row inserted into MySQL table, "ID" goes up by 1.
So e.g. if i add 5 rows.

ID: 1
ID: 2
ID: 3
ID: 4
ID: 5

But when i remove one.. e.g.

ID: 5

and add a new row, the ID of the new row is

ID: 6

So it goes:

ID: 1
ID: 2
ID: 3
ID: 4
ID: 6

Is there anyway to make it goto 5?
(if you know waht i mean)
Reply
#2

example:
pawn Код:
mysql_query("SELECT MAX(vehicleid) FROM vehicles");
    mysql_store_result();
    new SQL[20];
    mysql_fetch_row_format(SQL, "|");
    new sqlid = strval(SQL);
    mysql_free_result();
    format(string, sizeof(string), "ALTER TABLE `vehicles` AUTO_INCREMENT =%i", sqlid);
    mysql_query(string);
Reply
#3

Don't do that. It's not meant that game vehicleid is db vehicleid.
Reply
#4

Its called Auto Increment and also you must set index to "PRIMARY"
Reply
#5

pawn Код:
mysql_query("SELECT * FROM `player_data` ORDER BY `KILLS` DESC LIMIT 20");
- Selecting all lines from player_data
- Ordering it by kills
- In a descending format
- Limit is 20
Reply
#6

Quote:
Originally Posted by iTorran
Посмотреть сообщение
For each new row inserted into MySQL table, "ID" goes up by 1.
So e.g. if i add 5 rows.

ID: 1
ID: 2
ID: 3
ID: 4
ID: 5

But when i remove one.. e.g.

ID: 5

and add a new row, the ID of the new row is

ID: 6

So it goes:

ID: 1
ID: 2
ID: 3
ID: 4
ID: 6

Is there anyway to make it goto 5?
(if you know waht i mean)
No you can't do that afaik. However if you have a PRIMARY KEY then you can fix the key ID by using ANALYSE TABLE table_name;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)