Setting ID's of vehicles - SQL
#1

Does anyone know how I can make a command which re-orders the vehicle ID's in the database?

For example,

pawn Код:
for(new i=0;i<203;i++)
        {
         format(sql, sizeof(sql), "UPDATE cars SET id = %d", i);
             mysql_query(sql);
        }
Thanks.
Reply
#2

bump
Reply
#3

That's a bad question to answer. I think it would be better to build up your table the way it doesn't have to be reordered.

Do you care to explain a little deeper about how your vehicles system works and how the table is set up? And why would it need reordering in the first place?

Edit: Ooh, you meant it that way. All you need is ORDER BY then.
Reply
#4

It needs reordering because they are out of order..

Table:

id vehiclename model x y z angle
Reply
#5

Код:
SELECT * FROM cars ORDER BY id ASC
?
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
Код:
SELECT * FROM cars ORDER BY id ASC
?
:P

This reorders the results of a SQL statement, I need the physical fields reordered.
Reply
#7

pawn Код:
stock ResetVehicleID() {
    mysql_query("ALTER TABLE `vehicles` DROP id");
    mysql_query("ALTER TABLE `vehicles`  ADD id INT(5) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
}
something like this?
Reply
#8

Quote:
Originally Posted by Haydz
Посмотреть сообщение
pawn Код:
stock ResetVehicleID() {
    mysql_query("ALTER TABLE `vehicles` DROP id");
    mysql_query("ALTER TABLE `vehicles`  ADD id INT(5) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
}
something like this?
Nah this didn't do it. Hm..

There's 220 cars right, so I just want each id field for each car to go up from 1 - 220

EDIT: Wait it didn't even re-add the id field
Reply
#9

Don't worry, Haydz, it worked.

Thanks.

Sry for double post.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)