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 answers

i 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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -