There are two tables users and del , it is required to move one entry from the users table to the del table, users have an auto-increment. You need a transfer request from users=>del and del=>users , and at the same time save the id (auto increment).
2 answers
You can do the following:
START TRANSACTION; INSERT INTO del SELECT * FROM users WHERE id = 354; DELETE FROM users WHERE id = 354 LIMIT 1; COMMIT; In the transaction, we execute two queries - the first to copy the record with the selected id from the users table to the del table. The second is deleting the record from the table.
- Ok, I will try, there is not enough Limit :) - Denis Kotlyarov
- It seems to me here it is redundant, but I agree to start a query with LIMIT - a good habit, especially if you often work in the console :) - cheops
- Schyas for now, sorry, I can not protest, it will be a little different. Soon I’m going to work and if it works (and I think it will be so), I’ll put it +. - Denis Kotlyarov
|
Save the auto increment will be difficult. For example, mysqldump does not save the state of autoincrement. After the restoration of the database, the auto increment will take the nearest number. As an option, use the users_numerator table-enumerator with auto-increment, and associate with it users and del by id
|
delnot an option? update it instead of fancy transfers? - Yura Ivanov