Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

load command in mysql

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi all,
I'm trying to populate a table "myTable" in mySQL and I am doing it trough "load" and reading the input stored in a text file "file.txt".
Now "myTable" has more columns than "file.txt". My worry is to fill those colums too when I'm reading the "file.txt".
myTable is like this:
id
name
valu1
valu2

and file.txt is
name valu1 valu2


now, I have a separate table "table2" which has the mapping of
name-> id

So, while populating the table "myTable" through "file.txt", I want to fill "id" column also.

Can anyone tell me how to accomplish this ?
Thanks in advance.
abby
 
change youe file.txt to read like :
"","name","valu1","valu2"

and the load data local infile 'file.txt' fields enclosed by '"' terminated by ',' lines terminated by '\n' blah blah ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
woops, terminate dthe last field in each line with a , too.

"","name","valu1","valu2",
______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
hi KarveR,
Thanks for the reply. But I have a problem. What if I don't want to change the text file becaz its a large flat file. Is there anyway we can achieve loading the table without changing the text file ?
Thanks.
 
Is your file tab separated?
Are there any fields with spaces in?

If you have not got a tab separated file and there are spaces in the field you cannot specify how mysql should separate the fields and therefore will have load problems. - need to know more before offing more :)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top