mamdouh asked this 7 years ago

How to insert multiple rows into an SQL database using single query?

What is the SQL statement to insert multiple rows in to database table?

INSERT INTO members (name, age, ID) VALUES ('aron',33,1000);
INSERT INTO members (name, age, ID) VALUES ('ben',48,1000);
INSERT INTO members (name, age, ID) VALUES ('carl',20,1000);

How can I combine into single statement?


Best Answer by raj 7 years ago

There is no standard query that works on all databases.

In MySQL and SQL Server,

INSERT INTO members (name, age, ID) VALUES ('aron',33,1000), ('ben',48,1000), ('carl',20,1000);

In Oracle,

INSERT ALL 
INTO members (name, age, ID) VALUES ('aron',33,1000)
INTO members (name, age, ID) VALUES ('ben',48,1000)
INTO members (name, age, ID) VALUES ('carl',20,1000)
SELECT 1 FROM DUAL;