select into a table with different column names

前端 未结 1 1681
轮回少年
轮回少年 2021-02-12 12:43

In SQL, Select into ... copies rows into a different (backup) table. Is this possible if the backup table has different structure (or different column names)? If no

相关标签:
1条回答
  • 2021-02-12 12:59

    The column names do not matter at all, as long the data types match.

    If the data types of the columns don't match, try casting the values accordingly. Just try with small dummy tables. Be sure to list the target columns explicitly to avoid confusion. Like this:

    INSERT INTO TableB (b1, b2, b3)
    SELECT a1, a2, a3
    FROM   TableA
    WHERE <some condition>;
    

    More details in the SQLite manual here.

    0 讨论(0)
提交回复
热议问题