Can you duplicate a row without knowing the schema in MySQL? -
this question has answer here:
- in mysql, can copy 1 row insert same table? 23 answers
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
Post a Comment