Microsoft SQL Server insert from select query

前端 未结 1 822
误落风尘
误落风尘 2020-12-16 12:08

What I\'m trying to do: read the logs and insert the necessary data into 3 different tables that get information from each other.

LOG_ITEM201303 is foun

相关标签:
1条回答
  • 2020-12-16 12:21

    You can use the following syntax for inserts

    INSERT INTO dbo.Destination (Col1, Col2, Col3)
    SELECT Col1, Col2, Col3
    FROM dbo.Source
    

    If you had tables with the same columns or a result set that had the same columns as your destination, you don't have to specify columns in the INSERT.

    INSERT INTO dbo.Destination
    SELECT *
    FROM dbo.Source
    

    Both of these are predicated on your Destination table already being created. These are NOT the same as SELECT * INTO dbo.Destination FROM dbo.Source

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