I'm not sure how to formulate the title correctly. I'll try to elaborate, and make it understandable here.
I have a table with an auto_incremented ID (Primary Key). In the same table I have a guid-column. This guid is going to be an URL. So the guid will typically be something like http://www.example.com/path/path/ID
My question is this: Because the ID is auto-generated on INSERT, and I don't manually assign this, I dont know beforehand what the ID is going to be. How can I then assign the guid-value in the insert-statement, if I'm dependant on having the ID?
The solution I have at the moment is doing it with two statements:
INSERT INTO table (ID, guid) VALUES (null, null); I will now have a row that looks something like this:
------------- | ID | GUID | ------------- | 1 | null | ------------- I can then in another statement update this row with a statement like this;
UPDATE table SET guid = ID WHERE ID = 1; (Might be off-syntax, but you get the point)
Is there any way to do this in "one go"? Where I can set the GUID based off of what the auto_incremented ID is going to be? So it would be something like this
INSERT INTO table (ID, guid) VALUES (null, ID); I hope my question is understandable! I will clarify if it's still unclear. I don't know any better way to explain my question.
IDwill always be equal toGUID. Therefore theGUIDfield will always be redundant and unnecessary. Wouldn't it be better to develop a path, (assuming PHP) like$guid = "http://www.example.com/path/path/".$row['id'];where$row['id']is the result from your query?