Inserting from a SELECT but changing one column?

前端 未结 6 760
忘了有多久
忘了有多久 2021-02-05 02:35

Wondering if there is a way to insert a row into a table from another, with exception of one column?

This is of course easy with a limitied amount of columns, but gets k

6条回答
  •  失恋的感觉
    2021-02-05 03:10

    For SQL Server, the syntax would be:

    insert  into TargetTable
            (col1, col2, col3, ...)
    select  getdate(), col2, col3, ... 
    from    SourceTable
    

    SQL Server can generate a column list for you. Right click the table name, and choose Script as -> Select -> To New Window.

提交回复
热议问题