counter customizable free hit

Thursday, July 28, 2005

Multi Row inserts

One of the features I like best in MySQL is the ability to insert mulitple rows of data using a single insert statement. In Oracle you need to write an insert statement for each row including the list of columns each time, but in MySQL you only need to list the column names you need once and then list the values clause multiple times.

So in Oracle we have

insert into emps (emp_id, name, salary)
values (1,'Dave',2000.00);

insert into emps (emp_id, name, salary)
values (2,'John',2100.00);

insert into emps (emp_id, name, salary)
values (3,'Barry',1900.00);

But in MySQL this can be done like so.

insert into emps (emp_id, name, salary)
values (1,'Dave',2000.00),(2,'John',2100.00),(3,'Barry',1900.00)


It's shorter, tidy and more logical.

0 Comments:

Post a Comment

<< Home