SA-MP Forums Archive
MySQL Help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL Help (/showthread.php?tid=584459)



MySQL Help - Luis- - 04.08.2015

Okay, so I was wondering if this would be possible.

Say I have a vehicle table and a player table. The player table stores the players vehicle key (id), and the vehicle table stores the id (players key).

What I'm wanting to do is set up a relation view for the vehicles & players table so that when I delete a vehicle from the database, I would send the following query;
Код:
SELECT MAX(`ID`) FROM `server_vehicles`
ALTER TABLE `server_vehicles` AUTO_INCREMENT = MAX(`ID`);
So that the vehicle id's are still in order.

What currently happens is the players vehicle keys get mixed up cause of the last query I send.


Re: MySQL Help - Vince - 04.08.2015

Never alter a primary key, especially not like that. If a vehicle can be owned by one player only then all you need is an "ownerid" column in the vehicle table.


Re: MySQL Help - Luis- - 04.08.2015

But that wouldn't update the players vehicle key, they'd still get mixed up.


Re: MySQL Help - Vince - 05.08.2015

I don't get it. I'm assuming a player can own multiple carkeys and each carkey can be shared by multiple players, in which case you would need at least four tables:
Player and vehicle being the obvious ones. Then you need a third table that stores the combination userid - carkey. And a fourth table that stores the combination car - carkey.

I'd draw up a schematic, but it's 2AM so I'm going to bed.


Re: MySQL Help - Luis- - 05.08.2015

I had trouble typing it up, it is hard to understand.


What I'm hoping to achieve is when somebody deletes their vehicle, there'll be a gap in the ID row of the table, so it'll show like this, 1, 2, 4, 5, what I'd like to happen is the ID's get put back in order, so they'd show like this, 1, 2, 3, 4.

Then, what I'd want to happen is, the player vehicle id 5 as their carkey, it'd be set to 4 cause the ID row has been put back into order.