将数据从一个表复制到另一个表并更改ID

这个问题在这里已经有了答案:

  • 插入...值(SELECT ... FROM ...)21个答案

  • 尝试像这样的思想

    INSERT INTO work_done
              ( id
              , col2
               ...
              )
         SELECT 20
              , col2
               ...
          FROM work_todo WHERE id = 10
    

    select *
     into work_done
     from work_todo
    where id = 10;
    
    update work_done a
       set a.id = 20;
    

    要么

     select case id
                when id = 10
                  then id = 20
         into work_done
         from work_todo
        where id = 10;
    
    链接地址: http://www.djcxy.com/p/94315.html

    上一篇: Copy data from one table to another and change id

    下一篇: How can I SQL insert a record for every id in another table?