使用SQL Server 2012将多行插入临时表[复制](Insert Multiple Rows Into Temp Table With SQL Server 2012 [duplicate])

编程入门 行业动态 更新时间:2024-10-28 20:19:07
使用SQL Server 2012将多行插入临时表[复制](Insert Multiple Rows Into Temp Table With SQL Server 2012 [duplicate])

这个问题在这里已经有了答案:

如何插入多行而不重复声明中的“INSERT INTO dbo.Blah”部分? 12个答案

这里的这些StackOverflow问题, 在这里和这里都说同样的事情,但我不能让它在SSMS或SQLFiddle中运行

CREATE TABLE #Names
  ( 
    Name1 VARCHAR(100),
    Name2 VARCHAR(100)
  ) 

INSERT INTO #Names
  (Name1, Name2)
VALUES
  ('Matt', 'Matthew'),
  ('Matt', 'Marshal'),
  ('Matt', 'Mattison')
 

当我执行SSMS时,插入失败,并在VALUES后的第一行显示以下消息

Msg 102,Level 15,State 1,Line 10 ','附近的语法不正确。

小提琴运行时没有#号,并且在表名为#Names时成功执行模式,但当我尝试从表中选择*时,出现以下消息

无效的对象名称'#NAMES'.: SELECT * FROM #NAMES

SQL Server 2012是否支持多个插入?

更新对不起,你好。 SQL新手没有意识到SSMS 2012将被限制在我所在的任何服务器上

SELECT @@VERSION
--Returns: Microsoft SQL Server 2005 - 9.00.5057.00 (X64) 
--Mar 25 2011 13:33:31 
--Copyright (c) 1988-2005 Microsoft Corporation
--Standard Edition (64-bit) on Windows NT 5.2 (Build 3790: Service Pack 2)
 
 

This question already has an answer here:

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

These StackOverflow questions here, here, and here all say the same thing, but I can't get it to run in SSMS or SQLFiddle

CREATE TABLE #Names
  ( 
    Name1 VARCHAR(100),
    Name2 VARCHAR(100)
  ) 

INSERT INTO #Names
  (Name1, Name2)
VALUES
  ('Matt', 'Matthew'),
  ('Matt', 'Marshal'),
  ('Matt', 'Mattison')
 

When I execute this is SSMS, the insert fails with the following message on the first line after VALUES

Msg 102, Level 15, State 1, Line 10 Incorrect syntax near ','.

This Fiddle runs without the # sign, and the schema executes successfully when the table name is #Names, but I get the following message when I try to select * from the table

Invalid object name '#NAMES'.: SELECT * FROM #NAMES

Does SQL Server 2012 support multiple inserts?


Update: Apparently accessing a 2005 server on SSMS 2012....

SELECT @@VERSION --Returns: Microsoft SQL Server 2005

                

最满意答案

是的,SQL Server 2012支持多个插入 - 该功能是在SQL Server 2008中引入的。

这让我想知道您是否拥有Management Studio 2012,但您确实连接到了SQL Server 2005实例......

你从SELECT @@VERSION获得什么版本的SQL Server 引擎

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 ??

更多推荐

本文发布于:2023-08-02 08:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1373223.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:将多行   Insert   SQL   Server   Table

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!