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

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

    Your syntax almost works in SQL Server 2008 (but not in SQL Server 20051):

    CREATE TABLE MyTable (id int, name char(10));
    
    INSERT INTO MyTable (id, name) VALUES (1, 'Bob'), (2, 'Peter'), (3, 'Joe');
    
    SELECT * FROM MyTable;
    
    id |  name
    ---+---------
    1  |  Bob       
    2  |  Peter     
    3  |  Joe       
    

    1 When the question was answered, it was not made evident that the question was referring to SQL Server 2005. I am leaving this answer here, since I believe it is still relevant.

提交回复
热议问题