我想要的是在
mysql表中插入数据,但我无法找到从一行建立关系的方法
假设我有一个文件file.tab它包含类似的数据
parent_1 parent_details_1 child_1.1 child_details_1.1 child_1.2 child_details_1.2
parent_2 parent_details_2 child_2.1 child_details_2.1
parent_3 parent_details_3 child_3.1 child_details_3.1 child_3.2 child_details_3.2 child_3.3 child_details_3.3
我想要实现的是在两个表中插入数据
parent_table
+---+-----------+-------------------+
|id | name | details |
+---+-----------+-------------------+
| 1 | parent_1 | parent_details_1 |
| 2 | parent_2 | parent_details_2 |
| 3 | parent_3 | parent_details_3 |
+---+-----------+-------------------+
child_table
+---+-----+-----------+-------------------+
|id | pid | name | details |
+---+-----+-----------+-------------------+
| 1 | 1 | child_1.1 | child_details_1.1 |
| 2 | 1 | child_1.2 | child_details_1.2 |
| 3 | 2 | child_2.1 | child_details_2.1 |
| 4 | 3 | child_3.1 | child_details_3.1 |
| 5 | 3 | child_3.2 | child_details_3.2 |
| 6 | 3 | child_3.3 | child_details_3.3 |
+---+-----+-----------+-------------------+
前两列用于父级,之后两列属于子级,但我不知道父级有多少子级.
我试图以这种方式加载文件.
LOAD DATA INFILE '/tmp/file.tab INTO TABLE ...
但我接下来做什么我不知道.
所以请在这个问题上帮助我.