my problem is i can’t import an excel.cvs file to my sql database, because it does not have an index key.
here is the database structure:
+-----+------+-----+-----+---------+------+-------+----+
|from | to |cont |desc |date_time| total| amount| id |
+-----+------+-----+-----+---------+------+-------+----+
id being the primary with auto increment.
content of cvs file:
12345678910 17071234569 UNITED STATES OF AMERICA California 12/15/2012 2:41 4:00 0.04536
12345678910 17861234569 UNITED STATES OF AMERICA Florida 12/15/2012 2:41 4:00 0.076
cvs in notepad ++:
12345678910,17071234569,UNITED STATES OF AMERICA,California,12/15/2012 2:41,4:00,0.04536
12345678910,17861234569,UNITED STATES OF AMERICA,Florida,12/15/2012 2:41,4:00,0.076
when i import the cvs to my database, it always says i’m missing 1 colum which is the ID,
but when i make an ID column it always says there is no data on that column, and when i input a value on the ID column in the CVS file the ID on my database gets mixed up.
ex:
+---+
|ID |
+---+
|1 |
+---+
| |
+---+
|1 |
+---+
|2 |
what can be the solution here so that i can import my cvs even if it does not have an ID column, and the files that are imported to the database will get an ID automatically.
Let me explain in simple terms. Your table need 8 arguments and you are giving it only 7. It is possible when you are inserting a record using insert statement. In case of import you must have to give all the column details. You can’t leave a column even if it is auto-incremented. So you have to give the ID column your self.
Here is my suggestion: I don’t know how you got the CSV file but you can very much open the CSV file in MS-Excel. Now you know how easily you can add a column there and you can generate sequence there in just multiple click.
After inserting records in your table you can know how many rows you have. Now use this command in the SQL prompt or you can always find one SQL prompt in your PHPMyAdmin: