Can you duplicate a row without knowing the schema in MySQL? -


this question has answer here:

a great way duplicate row in mysql use insert ... select from syntax.

for example:

insert tblexample (col1, col2, col3) select col1, col2, col3 tblexample pkey = 1234; 

this easy , straightforward, code maintenance standpoint 1 more statement keep track of if there schema changes. suppose add additional column tblexample table, col4; have remember go , update sql statement in code. if fail so, i've introduced bug.

with in mind, there easy way copy whole row, whatever schema may be, except primary key?

a inelegant way:

create temporary table tmptable engine=memory select * realtable pk = 'something'; update tmptable set pk = 'something else' ; insert realtable select * tmptable; 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -