Move SQL data from one table to another

后端 未结 13 2901
梦如初夏
梦如初夏 2020-11-29 20:34

I was wondering if it is possible to move all rows of data from one table to another, that match a certain query?

For example, I need to move all table rows from Tab

13条回答
  •  囚心锁ツ
    2020-11-29 21:17

    Should be possible using two statements within one transaction, an insert and a delete:

    BEGIN TRANSACTION;
    INSERT INTO Table2 ()
    SELECT 
    FROM Table1
    WHERE ;
    
    DELETE FROM Table1
    WHERE ;
    
    COMMIT;
    

    This is the simplest form. If you have to worry about new matching records being inserted into table1 between the two statements, you can add an and exists .

提交回复
热议问题