SQL insert for multiple write

I get an error when I run the following query in MSSQL Server 2005 .

Incorrect syntax near ',' error message. I think the question is ok. But I do not know why I am wrong.

 INSERT INTO PERSON (ID, EMP_NAME) VALUES ('E001', 'AAA'), ('E002', 'BBB'); 

SQL Server does not support?

+4
source share
3 answers

If your database following SQL Server 2008

 INSERT INTO PERSON (ID, EMP_NAME) VALUES ('E001', 'AAA'); INSERT INTO PERSON (ID, EMP_NAME) VALUES ('E002', 'BBB'); 
+6
source

Try using UNION ALL -

 INSERT INTO Person (id, EMP_NAME) SELECT id = 'E001', EMP_NAME = 'AAA' UNION ALL SELECT 'E002', 'BBB' 
+4
source

Try the following:

 INSERT INTO Person (id, EMP_NAME) SELECT 'E001', 'AAA' UNION ALL SELECT 'E002', 'BBB' 
+3
source

Source: https://habr.com/ru/post/1493594/


All Articles