Reputation: 199
I need to insert around 500-1000 rows into a table in mysql database.Here is the sample insert query for my table
INSERT INTO `jtbillingtest`.`at_user`
(`clientGuid`,
`clientFirstName`,
`clientMiddleName`,
`clientLastName`,
`gender`,
`clientAddress`,
`clientMobileNumber`,
`clientEmailID`,
`clientTypeCode`,
`active`)
VALUES
(
<{clientGuid: }>,
<{clientFirstName: }>,
<{clientMiddleName: }>,
<{clientLastName: }>,
<{gender: }>,
<{clientAddress: }>,
<{clientMobileNumber: }>,
<{clientEmailID: }>,
<{clientTypeCode: }>,
<{active: Yes}>
);
And My table structure is
CREATE TABLE `at_user` (
`clientGuid` int(11) NOT NULL AUTO_INCREMENT,
`clientFirstName` varchar(45) DEFAULT NULL,
`clientMiddleName` varchar(45) DEFAULT NULL,
`clientLastName` varchar(45) DEFAULT NULL,
`gender` varchar(10) DEFAULT NULL,
`clientAddress` varchar(45) DEFAULT NULL,
`clientMobileNumber` varchar(45) NOT NULL,
`clientEmailID` varchar(45) DEFAULT NULL,
`clientTypeCode` varchar(2) DEFAULT NULL COMMENT 'Client Type code will determine whether it is a sales customer ,purchase customer ,employee or store owner.',
`active` varchar(45) NOT NULL DEFAULT 'Yes',
PRIMARY KEY (`clientGuid`),
UNIQUE KEY `UK_CLIENTMNILENUMBER` (`clientMobileNumber`),
UNIQUE KEY `clientGuid_UNIQUE` (`clientGuid`),
UNIQUE KEY `UK_CLIENTEMAILID` (`clientEmailID`),
KEY `IX_CLIENTGUID` (`clientGuid`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 COMMENT='THis Table is used to store the user details'$$
please can someone help me to insert these many rows using any scripts or any other easier way ?
Upvotes: 1
Views: 695
Reputation: 26804
This would be the general idea of a php script
for($i=0;$i<count($numrows);$i++){
$sql_query = "INSERT INTO table (column1, column2 column3) VALUES ('$value1[$i]','$value2[$i]','$value3[$i]')";
}
If you can get the data into php
Upvotes: 0
Reputation: 750
Try with the following link it will help you:
http://www.electrictoolbox.com/mysql-insert-multiple-records/
INSERT INTO example
(example_id, name, value, other_value)
VALUES
(100, 'Name 1', 'Value 1', 'Other 1'),
(101, 'Name 2', 'Value 2', 'Other 2'),
(102, 'Name 3', 'Value 3', 'Other 3'),
(103, 'Name 4', 'Value 4', 'Other 4');
Upvotes: 1