简体   繁体   English

SQL Server 2005中的插入语句

[英]Insert statement in SQL Server 2005

I have strange problem related to SQL Server 2005 我有与SQL Server 2005相关的奇怪问题

When I try to insert into table 当我尝试插入表格中

insert into IDName
VALUES (101 , 'AA'),
       (301 , 'BB')

I receive this error 我收到此错误

Msg 102, Level 15, State 1, Line 3 Msg 102,第15级,状态1,第3行
Incorrect syntax near ','. ','附近的语法不正确。

There is no problem, if I insert records one by one. 没问题,如果我一一插入记录。

EDIT: Thanks for reply guys.... but this script works in other installation of sql server 2005... I think it is some setting issue but i do not where... if you could help 编辑:感谢您的答复。...但是此脚本在sql server 2005的其他安装中有效...我认为这是一些设置问题,但我不在哪里...如果您可以帮助的话

This syntax was introduced in SQL Server 2008. So upgrade, or use the more verbose: 此语法是SQL Server 2008中引入的。因此,请升级或使用更详细的说明:

INSERT dbo.IDName(column1, column2)
  SELECT 101 , 'AA'
  UNION ALL SELECT 301 , 'BB';

Some additional changes: 一些其他更改:

  1. Always use the schema prefix when referencing objects 引用对象时始终使用架构前缀
  2. Always specify the column list for an INSERT 始终为INSERT指定列列表
  3. Always use semi-colons to terminate statements 始终使用分号终止语句

SQL Server 2005 does not support that insert syntax; SQL Server 2005不支持该插入语法。 you would either need 你要么需要

insert into IDName 
SELECT 101 , 'AA'
UNION ALL SELECT 301 , 'BB'

or 要么

insert into IDName VALUES (101 , 'AA');
insert into IDName VALUES (301 , 'BB');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM