Insert multiple rows WITHOUT repeating the “INSERT INTO …” part of the statement?

前端 未结 15 1875
广开言路
广开言路 2020-11-22 09:16

I know I\'ve done this before years ago, but I can\'t remember the syntax, and I can\'t find it anywhere due to pulling up tons of help docs and articles about \"bulk import

15条回答
  •  清酒与你
    2020-11-22 09:49

    You can use a union:

    INSERT INTO dbo.MyTable (ID, Name) 
    SELECT ID, Name FROM (
        SELECT 123, 'Timmy'
        UNION ALL
        SELECT 124, 'Jonny'
        UNION ALL
        SELECT 125, 'Sally'
    ) AS X (ID, Name)
    

提交回复
热议问题