Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > create table t(id int UNIQUE,v varchar(10)); > > <pre> > ✓ > </pre> <!-- --> > insert into t (id,v) > values (2,'c'),(3,'a'), (5,'b'); > > <pre> > ✓ > </pre> <!-- --> > select * from t > > <pre> > id | v > -: | :- > 2 | c > 3 | a > 5 | b > </pre> <!-- --> > CREATE PROCEDURE procedure_name(IN _a BIGint , IN _b BIGint) > BEGIN > CREATE TEMPORARY TABLE T1 SELECT _b,v FROM t WHERE id = _a; > DELETE FROM t WHERE id = _a; > UPDATE t SET id = _a WHERE id = _b; > INSERT INTO t SELECT * FROM T1; > END > > <pre> > ✓ > </pre> <!-- --> > CALL procedure_name(3,5) > > <pre> > ✓ > </pre> <!-- --> > select * from t > > <pre> > id | v > -: | :- > 2 | c > 3 | b > 5 | a > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=1286dbb0574faa9df93af1ec269d8617)*
back to fiddle