1

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 ?

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
Firu
  • 199
  • 1
  • 5
  • 15

2 Answers2

1

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');
Lóri Nóda
  • 694
  • 1
  • 10
  • 20
  • 4
    While it is OK to post a link on SO, it is encouraged to include the meat of the answer found under that link in your own answer, as the link may expire / disappear, which would make your answer useless if it didn't include the main points. See alse [_Provide context for links_ in the FAQ](http://stackoverflow.com/help/how-to-answer) – Wrikken Sep 29 '13 at 18:47
0

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

Mihai
  • 26,325
  • 7
  • 66
  • 81