简体   繁体   English

如何在 SAP 字典表中查找外键?

[英]How to find ForeignKey in SAP Dictionary tables?

Table AUFK has a column called ADRNRA .AUFK有一个名为ADRNRA的列。

The values in column ADRNRA have matching rows in table ADRC . ADRNRA 列中的值在表ADRC中具有匹配的行。

In this case I found ADRC because someone told me the solution.在这种情况下,我找到了 ADRC,因为有人告诉我解决方案。

Maybe I am blind, but it looks like AUFK-ADRNRA is no explicit foreign key.也许我是盲人,但看起来 AUFK-ADRNRA 没有明确的外键。

Is there a way to do introspection and find the matching related table (in this example ADRC) with a script or with SQL?有没有一种方法可以使用脚本或 SQL 进行自省并找到匹配的相关表(在此示例中为 ADRC)?

Indeed the field is not marked as foreign key of the field ADDRNUMBER of the table ADRC but should you have looked at the domain of the field ADRNRA of the table AUFK you would have found the reference in just a few seconds.事实上,该字段未标记为表ADRC的字段ADDRNUMBER的外键,但如果您查看了表AUFK的字段ADRNRA的域,您会在几秒钟内找到引用。

The domain (in this case AD_ADDRNUM ) has an explicitly specified value table which is, surprise, surprise, ADRC .域(在本例中AD_ADDRNUM )有一个明确指定的值表,即 surprise, surprise, ADRC

领域

值表

Nope, there is no easy way to reveal foreign keys in an SAP system.不,没有简单的方法来揭示 SAP 系统中的外键。 :-( :-(

Database management systems don't require you to model foreign keys.数据库管理系统不需要您为外键建模。 You only do that when you want to enforce constraints such as "must refer to a row in the other table" and automatic reactions such as cascading deletion ("delete this row if its 'parent' row in the other table is deleted").只有当您想要强制执行约束(例如“必须引用另一个表中的行”)和自动反应(例如级联删除(“如果删除另一个表中的‘父’行,则删除该行”))时,您才这样做。

Older SAP applications implemented constraints and reactions like these in the application layer, ie the ABAP code.较旧的 SAP 应用程序在应用程序层(即 ABAP 代码)中实现了类似的约束和反应。 They didn't have a need for modeled relations, and thus people simply didn't model them.他们不需要模型化的关系,因此人们根本就不会对它们进行建模。

Common means to identify foreign key relationships are:识别外键关系的常用方法有:

  • Asking experienced users or the people who designed the database model.询问有经验的用户或设计数据库模型的人。
  • Guessing, from identical column names and data types.猜测,来自相同的列名和数据类型。
  • Inspecting the application code and seeing what tables it joins.检查应用程序代码并查看它加入了哪些表。

There are also some experimental machine learning algorithms that try to detect relations;还有一些实验性的机器学习算法试图检测关系; google "foreign key discovery" for more information.谷歌“外键发现”以获取更多信息。

As @Sandra points out in her comment, newer SAP applications reveal a lot more relationships because they use CDS views.正如@Sandra 在她的评论中指出的那样,较新的 SAP 应用程序揭示了更多的关系,因为它们使用 CDS 视图。 Modeling relationships there has direct benefits such as automatically generating associations in OData services, selecting along relations, and using them to model business objects.在那里建模关系有直接的好处,例如在 OData 服务中自动生成关联,选择关系,并使用它们来建模业务对象。

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

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