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

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

    USE YourDB
    GO
    INSERT INTO MyTable (FirstCol, SecondCol)
    SELECT 'First' ,1
    UNION ALL
    SELECT 'Second' ,2
    UNION ALL
    SELECT 'Third' ,3
    UNION ALL
    SELECT 'Fourth' ,4
    UNION ALL
    SELECT 'Fifth' ,5
    GO
    

    OR YOU CAN USE ANOTHER WAY

    INSERT INTO MyTable (FirstCol, SecondCol)
    VALUES 
    ('First',1),
    ('Second',2),
    ('Third',3),
    ('Fourth',4),
    ('Fifth',5)
    

提交回复
热议问题