View Single Post
xRENN1Ex
Junior Member
Join Date: Dec 2019
Old 12-28-2019 , 15:13   Re: SQL Insert and Update Player Info
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
You need to include a primary key in the statement otherwise it will work the same as insert. If any fields in the record have a value then you must include them in the statement, even if they are not being changed, otherwise they will be set to null. In the below example my primary key in the table is ID, set to auto-increment to make inserting new records easy.

Suppose I have the below record:

ID = 223
SteamID = STEAM_0:1:12345
PlayerName= bugsy
PlayTime= 555

I can then do the below to update PlayTime to 123. Fields SteamID & PlayerName will remain unchanged since I am including the existing values in the statement.

Code:
REPLACE INTO tblPlayerData (ID, SteamID, PlayerName, PlayTime) VALUES (223,'STEAM_0:0:12345','bugsy',123);
If I also have a column XPPoints in the table, it would be set to null with the above REPLACE INTO statement, unless I specify a value.

Assume these fields exist in a row:

ID = 223
SteamID = STEAM_0:1:12345
PlayerName= bugsy
PlayTime= 555
XPPoints = 555

Code:
REPLACE INTO tblPlayerData (ID, SteamID, PlayerName, PlayTime, XPPoints) VALUES (223,'STEAM_0:0:12345','bugsy',123,555);
This will retain XPPoints value of 555 (and leave SteamID & PlayerName as is), while changing PlayTime to 123.

When adding a new record, just exclude the ID field and it will add a new record, advancing ID to the next slot automatically.

Code:
REPLACE INTO tblPlayerData (SteamID, PlayerName) VALUES ('STEAM_0:0:555','bugsy2');


thank you for the answer

so can you ask me to do this sma coding

I don't have many resources because I am Turkish so I will be forced

I need help because it has a different structure than php
xRENN1Ex is offline