开发者

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

开发者 https://www.devze.com 2023-02-24 05:33 出处:网络
i h开发者_Python百科ave a mysql column called roles, i would like to insert many values at once instead of one value per query.

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消