The AUTO_INCREMENT mechanism has a restriction; you can only provide one column of the table with it and you have it assigned to the id column. To duplicate a value, the easiest way is to use a trigger:
CREATE TRIGGER id_to_thread BEFORE INSERT ON post FOR EACH ROW BEGIN SET @id := (SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'post' AND TABLE_SCHEMA=DATABASE() ); SET NEW.thread = @id; END//
In the trigger, the information scheme determines which value will be assigned to the id id by the AUTO_INCREMENT mechanism. The resulting value is assigned to the thread field before inserting an entry into the post table.
In order for the analyzer to separate the end of the request from the semicolons in the body of the trigger, you need to change the sign of the end of the request (for example, to //). In the mysql console, a special DELIMITER command is used for this.
DELIMITER //
Most other mysql clients also have the ability to flag the end of a query.
update tabX set thread=id where id=NEW.id and thread is null- Mike