You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取Progress DB中表间关系及指定表的外键关联信息

Hey there! Let's break down how to figure out table relationships and verify foreign keys in Progress DB, especially for your OrderDetail table example with fields Date, Product_Id, Order_Id, and Quantity.

1. Get Overall Table Relationships in Progress DB

Progress OpenEdge maintains system catalog tables that store metadata about constraints, tables, and columns. You can query these to pull all cross-table relationships:

SELECT 
  ft.table_name AS foreign_table,
  fk.column_name AS foreign_column,
  pt.table_name AS primary_table,
  pk.column_name AS primary_column
FROM 
  sysconstraint sc
  JOIN syscolumn fk ON sc.constraint_id = fk.constraint_id AND sc.constraint_type = 'F'
  JOIN syscolumn pk ON sc.ref_constraint_id = pk.constraint_id
  JOIN systable ft ON fk.table_id = ft.table_id
  JOIN systable pt ON pk.table_id = pt.table_id
ORDER BY 
  foreign_table, foreign_column;

This query joins the system tables to map every foreign key column to its corresponding primary key table and column.

2. Check Specific Table Relationships (e.g., OrderDetail)

To confirm if Product_Id and Order_Id are foreign keys in OrderDetail, tweak the query above to filter for your target table:

SELECT 
  fk.column_name AS foreign_column,
  pt.table_name AS referenced_primary_table,
  pk.column_name AS referenced_primary_column
FROM 
  sysconstraint sc
  JOIN syscolumn fk ON sc.constraint_id = fk.constraint_id AND sc.constraint_type = 'F'
  JOIN syscolumn pk ON sc.ref_constraint_id = pk.constraint_id
  JOIN systable ft ON fk.table_id = ft.table_id
  JOIN systable pt ON pk.table_id = pt.table_id
WHERE 
  ft.table_name = 'OrderDetail'
ORDER BY 
  foreign_column;

If Product_Id and Order_Id show up in the results, they’re confirmed as foreign keys. You’ll also see which primary tables they link to—typically Product_Id points to a Product table’s primary key (like Id), and Order_Id links to an Order table’s primary key.

3. Alternative: Verify via Progress Tools

If you prefer a GUI or command-line approach instead of SQL:

  • OpenEdge Explorer: Navigate to your database, find the OrderDetail table, and check the "Constraints" section—foreign keys will be listed with their referenced tables.
  • Command Line with dbtool: Run this command to list all constraints for OrderDetail:
    dbtool -db your_database_name -listconstraints OrderDetail
    
    Look for entries marked as "FOREIGN KEY" to confirm Product_Id and Order_Id’s status.

内容的提问来源于stack exchange,提问作者cagin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:07:53