i h开发者_Python百科ave 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?
You can do something like this
INSERT INTO
roles(roleName)
VALUES ('Admnistrator'),
('SuperUser'),
('Staff'),
('Customers');
Yes, You can do:
INSERT INTO roles(roleName) VALUES('Admnistrator'),
('SuperUser'),
('Staff'),
('Customers');
INSERT INTO `roles` (`roleName`)
VALUES ('Admnistrator'),
VALUES ('SuperUser'),
VALUES ('Staff'),
VALUES ('Customers');
Just comma separate them.
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);
精彩评论