【问题标题】:Insert Data into MySQL using JDBC that have reference to another table使用 JDBC 将引用另一个表的数据插入 MySQL
【发布时间】:2015-09-01 15:31:47
【问题描述】:

我的数据库中有两个表(我使用 MySQL 和 xampp 作为工具)。我需要向数据库中插入 5000 个数据,其中一个列引用了另一个表中的另一列。

这是我的桌子。

表字典

dict_id |         dictionary        |
------------------------------------
   1    | I know You were in trouble|
   2    | Good to see you           |
   3    | What are you doing?       |
   .    |          . . .            |
   .    |          . . .            |
 5000   |          . . .            |

表格状态

user_id | dict_id | status|
---------------------------
    1   |    2    | bad   |
    1   |    1    | good  |
    1   |    3    | bad   |
    2   |    1    | bad   |
    3   |    3    | good  |
---------------------------

我已经完成了我的表格字典。我的问题是如何对我的餐桌状态做到这一点?我有 500 个用户和 5000 多个数据。我需要手动存储吗?我应该做些什么?我没有任何线索可以这样做。

【问题讨论】:

    标签: java mysql database xampp


    【解决方案1】:

    我认为您正在寻找 INSERT ... SELECT ... https://dev.mysql.com/doc/refman/5.0/en/insert-select.html

    INSERT INTO status SELECT dict_id, user_id FROM dictionary, users WHERE ....
    

    不清楚 user_id 或 status 真正来自哪里,但这可能是一个好的开始?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-20
      • 2013-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-20
      • 1970-01-01
      相关资源
      最近更新 更多