Reputation: 5980
Is there a way to set the value of another column to primary key (auto increment)?
Basically what I am trying to achieve is this
ID Stuff
---- ------
1 1
2 324
3 64
4 94
5 ...
Now when I am adding the the fifth row with a query like
INSERT into TABLE values(NULL, NULL);
So when the second value is NULL
I want it to be equal to ID.
I tried INSERT triggers but it doesnt work. Any ideas?
Upvotes: 2
Views: 1232
Reputation: 55643
Try this:
INSERT INTO `TABLE` (`ID`,`Stuff`) VALUES(NULL, `ID`);
Upvotes: 0
Reputation: 12463
One possibility is to expose a stored procedure, and when the Stuff parameter is null, update the insert with the LAST_INSERT_ID(), otherwise pass the non-null value to the insert.
Upvotes: 0
Reputation: 12837
I don't think you can do that in one step, but you can first insert and then update...
Upvotes: 1