简体   繁体   English

不使用主键将CSV文件导入到Mysql表

[英]Import CSV File to Mysql Table Without Primary Key

im trying to import a csv file containing these columns: 我正在尝试导入包含以下列的csv文件:

foreignKey, date, lobby 外键,日期,大厅

so, mysql table should look like this: 因此,mysql表应如下所示:

CREATE TABLE Patient( 
foreignKey int not null, 
date datetime not null, 
lobby int not null, 
foreign key(foreignKey)references Foreign(Id));

as you noticed, my table does not have a primary key, I tried to add JPA entities to my project, but it does not recognize this tables due table does not have a PK. 如您所见,我的表没有主键,我试图将JPA实体添加到我的项目中,但是由于该表没有PK,所以它无法识别该表。

Any advices about this issue on my code fellas? 关于我的代码小伙子对此问题的任何建议吗?

kudos! 赞!

I would suggest adding a primary key to the table with auto_integer 我建议使用auto_integer将主键添加到表中

You should be able to import your CSV with LOAD DATA INFILE : 您应该能够使用LOAD DATA INFILE导入CSV:

load data local infile 'myData.csv' 
into table Patient fields terminated by ','
enclosed by '"'
lines terminated by '\n'
(foreignKey, date, lobby)

Make sure to remove headings from the CSV and change the delimiters as per your CSV file if necessary. 确保从CSV删除标题,并根据需要根据CSV文件更改定界符。

LOAD DATA INFILE - MySQL 加载数据文件-MySQL

我必须使用JDBC驱动程序连接到数据库,真正不需要外部表上的主键,因此,我在数据库的每个表上创建了通用存储库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM