I have multiple set of data to insert at once, can i insert multiple rows in a single SQL statement -
I have multiple set of data to insert at once, can i insert multiple rows in a single SQL statement -
this question has reply here:
inserting multiple rows in single sql query? [duplicate] 4 answersi have multiple set of info insert @ once
insert mytable values ("john", 123, "lloyds office"); insert mytable values ("jane", 124, "lloyds office"); insert mytable values ("billy", 125, "london office"); insert mytable values ("miranda", 126, "bristol office");
can insert multiple rows in single sql statement
multi-row insert has been part of sql standard since sql-92, , many of modern dbms' back upwards it. allow like:
insert mytable ( name, id, location) values ('john', 123, 'lloyds office'), ('jane', 124, 'lloyds office'), ('billy', 125, 'london office'), ('miranda', 126, 'bristol office');
you'll notice i'm using full form of insert into
there, listing columns use. prefer since makes immune whatever order columns default to.
if particular dbms not back upwards it, part of transaction depends on dbms looks like:
begin transaction; insert mytable (name,id,location) values ('john',123,'lloyds office'); insert mytable (name,id,location) values ('jane',124,'lloyds office'), insert mytable (name,id,location) values ('billy',125,'london office'), insert mytable (name,id,location) values ('miranda',126,'bristol office'); commit transaction;
this makes operation atomic, either inserting values or inserting none.
sql
Comments
Post a Comment