简体   繁体   English

MySQL将行复制并粘贴到同一表的末尾

[英]mySQL copy and paste row to end of same table

I have a mysql table called users that has a unique id column plus loads of other columns, too many to list. 我有一个名为users的mysql表,该表具有唯一的id列以及其他列的负载,无法列出。

Is it possible to duplicate a specific row data using id and add it to the end of the table with a new ID without having to list each column name? 是否可以使用id复制特定的行数据并将其添加到具有新ID的表末尾而不必列出每个列名?

Assuming the id column is auto-incremented, you can do what you want by listing the columns as: 假设id列是自动递增的,则可以通过将列列出为以下内容来执行所需的操作:

insert into t(. . .)  -- all but id
    select . . .   -- all but id
    from t
    where id = @id;

You can get the columns to list using information_schema : 您可以使用information_schema获取要列出的列:

select group_concat(column_name)
from information_schema.columns
where table_schema = @schema and table_name = @name and
      column_name <> 'id';

You can copy and paste the columns into the above query. 您可以将这些列复制并粘贴到上面的查询中。 Or, you could even put the values in a variable, construct the SQL statement, and use prepare . 或者,您甚至可以将值放入变量中,构造SQL语句,然后使用prepare

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM