insert multiple values into table mysql code example

Example 1: insert data into multiple tables mysql

BEGIN;
INSERT INTO users (username, password)
  VALUES('test', 'test');
INSERT INTO profiles (userid, bio, homepage) 
  VALUES(LAST_INSERT_ID(),'Hello world!', 'http://www.stackoverflow.com');
COMMIT;

Example 2: mysql best way to insert many rows

INSERT INTO table_name(id,colname) values(1,"row 1"),(2, "row 2"),...;

Example 3: mysql insert into multiple tables

BEGIN;
INSERT INTO users (username, password)
  VALUES('test', 'test');
INSERT INTO profiles (userid, bio, homepage) 
  VALUES(LAST_INSERT_ID(),'Hello world!', 'http://www.stackoverflow.com');
COMMIT;

Tags:

Sql Example