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

前端 未结 15 2032
广开言路
广开言路 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条回答
  •  -上瘾入骨i
    2020-11-22 09:29

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

    For SQL Server 2008, can do it in one VALUES clause exactly as per the statement in your question (you just need to add a comma to separate each values statement)...

提交回复
热议问题