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

前端 未结 15 2149
广开言路
广开言路 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:38

    This looks OK for SQL Server 2008. For SS2005 & earlier, you need to repeat the VALUES statement.

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

    EDIT:: My bad. You have to repeat the 'INSERT INTO' for each row in SS2005.

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

提交回复
热议问题