Insert Multiple Rows Into Temp Table With SQL Server 2012

This question already has an answer here:

  • How do I insert multiple rows WITHOUT repeating the “INSERT INTO dbo.Blah” part of the statement? 12 answers

  • Yes, SQL Server 2012 supports multiple inserts - that feature was introduced in SQL Server 2008 .

    That makes me wonder if you have Management Studio 2012, but you're really connected to a SQL Server 2005 instance ...

    What version of the SQL Server engine do you get from SELECT @@VERSION ??


    When using SQLFiddle, make sure that the separator is set to GO. Also the schema build script is executed in a different connection from the run script, so a temp table created in the one is not visible in the other. This fiddle shows that your code is valid and working in SQL 2012:

    SQL Fiddle

    MS SQL Server 2012 Schema Setup :

    Query 1 :

    CREATE TABLE #Names
      ( 
        Name1 VARCHAR(100),
        Name2 VARCHAR(100)
      ) 
    
    INSERT INTO #Names
      (Name1, Name2)
    VALUES
      ('Matt', 'Matthew'),
      ('Matt', 'Marshal'),
      ('Matt', 'Mattison')
    
    SELECT * FROM #NAMES
    

    Results :

    | NAME1 |    NAME2 |
    --------------------
    |  Matt |  Matthew |
    |  Matt |  Marshal |
    |  Matt | Mattison |
    

    Here a SSMS 2012 screenshot: 在这里输入图像描述

    链接地址: http://www.djcxy.com/p/94506.html

    上一篇: 在SQL Server中插入100万行的最快方法

    下一篇: 使用SQL Server 2012将多行插入到临时表中