简体   繁体   English

如何在没有联接的情况下查询多个相关表,并使用JDBC获得一致的数据?

[英]How can I query multiple related tables, without a join, and get consistent data using JDBC?

I am creating a process that connects to a given SQL Server database via JDBC, scans every table, and reads any new data that has been inserted or updated since the last run of this process. 我正在创建一个通过JDBC连接到给定SQL Server数据库,扫描每个表并读取自该过程的上次运行以来已插入或更新的任何新数据的过程。 The owner of the database will not allow this process to do joins on any of the tables due to performance concerns. 由于性能方面的考虑,数据库的所有者不允许此过程对任何表进行联接。

The scenario in question 有关方案

  • Table A is a parent of table B 表A是表B的父级
  • This process reads data from Table A 此过程从表A中读取数据
  • Prior to the process reading Table B, a new parent record is inserted into Table A and new child records are inserted into Table B 在读取表B的过程之前,将新的父记录插入表A,并将新的子记录插入表B。
  • When Table B is read, there will be child records present that don't have a corresponding parent record in the result set from the previous read of Table A 读取表B时,在先前表A的读取结果集中,将存在子记录,这些子记录没有对应的父记录。

How can I query multiple related tables, without a join, and get consistent data using JDBC? 如何在没有联接的情况下查询多个相关表,并使用JDBC获得一致的数据?

If you cannot do JOINs, you probably then just have to keep track of each retrieved primary key of each parent table and then use those for querying the child rows. 如果您不能执行JOIN,则可能只需要跟踪每个父表的每个检索到的主键,然后使用那些键来查询子行。 It will complexify the queries, and add more strain to the DB, as you're executing more queries vs doing it in a single JOINed query, but it should give the same results. 与在单个JOINed查询中执行更多查询相比,这将使查询复杂化,并给数据库增加更多压力,但是它应该给出相同的结果。

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

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