简体   繁体   中英

Insert statement in SQL Server 2005

I have strange problem related to 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
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

This syntax was introduced in SQL Server 2008. So upgrade, or use the more verbose:

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
  3. Always use semi-colons to terminate statements

SQL Server 2005 does not support that insert syntax; 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');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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