Ibrahim Azhar Armar
Ibrahim Azhar Armar

Reputation: 25745

how do i insert many values in a column in single query?

i have a mysql column called roles, i would like to insert many values at once instead of one value per query.

for example instead of making four queries to insert four values

INSERT INTO roles(roleName) VALUES('Admnistrator');
INSERT INTO roles(roleName) VALUES('SuperUser');
INSERT INTO roles(roleName) VALUES('Staff');
INSERT INTO roles(roleName) VALUES('Customers');

i would like it to make one single query. is it possible?

Upvotes: 2

Views: 144

Answers (4)

mystertyboy
mystertyboy

Reputation: 479

Inserting the multiple row into a mysql database using a single query. You just need to add the other values in the values section with comma separated.

Insert INTO Table_name (coulmn1 , column2, column3) 
VALUES (row1value,row1value,row1value),
       (row2value,row2value,row2value),
       (row3value,row3value,row3value);

Upvotes: 0

alex
alex

Reputation: 490173

INSERT INTO `roles` (`roleName`) 
     VALUES ('Admnistrator'),
     VALUES ('SuperUser'),
     VALUES ('Staff'),
     VALUES ('Customers');

Just comma separate them.

Upvotes: 0

vietean
vietean

Reputation: 3033

Yes, You can do:

INSERT INTO roles(roleName) VALUES('Admnistrator'),
('SuperUser'),
('Staff'),
('Customers');

Upvotes: 0

ace
ace

Reputation: 6825

You can do something like this

INSERT INTO 
         roles(roleName) 
  VALUES ('Admnistrator'), 
         ('SuperUser'), 
         ('Staff'), 
         ('Customers');

Upvotes: 2

Related Questions