表不可知的外键? [英] Table-agnostic Foreign Keys?

查看:141
本文介绍了表不可知的外键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我读了这个StackOverflow的问题,所以不需要指向我。



我现在正在处理类似的问题。具体来说,我有一个数据库与审计表,用于存储有关数据库中的其他表的审计信息。这个表的基本形式是:

ID,EntityID,EntityTypeID,ActionTypeID,DateTime

现在,你可以猜测,EntityID的通用性意味着来自和来自这个表的外键关系是很难管理的,尤其是当你通过一个ORM系统进入混合。



当然,grunt-work解决方案是手动执行所需的查询,并在其工作的地方使用ORM的东西,我很好。



然而,问题在我脑海里提出的问题是,是否存在任何允许表单的外键关系的RDBMS:表:ID被定义



换句话说,在这样的RDBMS中,EntityTypeID列可能包含诸如

'TableA:1'和'TableB:somekey'



所以...

有没有这样的RDBMS?


First, I did read this StackOverflow question, so no need to point me towards it.

I'm working on a similar problem right now. Specifically, I have a database with an Auditing table that is used to store auditing info about other tables within the db. The basic form of this table is:

ID, EntityID, EntityTypeID, ActionTypeID, DateTime

Now, as you can guess, the generic nature of EntityID means that foreign key relationships to and from this table are tricky to manage, especially with you through an ORM system into the mix.

Of course, the grunt-work solution is to do the required queries manually and use the ORM stuff where it works, which I'm fine with.

However, the issue did raise the question in my mind as to whether or not there exists any RDBMS out there that allows for a Foreign Key relationship of the form: Table:ID to be defined.

In other words, in such an RDBMS, the EntityTypeID column might contains values such as

'TableA:1' and 'TableB:somekey'

So...

Is there any RDBMS which does this?

解决方案

Audit tables usually cannot have referential integrity constraints on them. An audit table, A, records information about a row of data, R, in some table, T, and contains a series of records for R, each representing R at some a different time. When R is subsequently modified, the information in A does not change, and is not allowed to prevent changes to R. When R is subsequently deleted, the presence of the audit records in A is not allowed to stop that deletion.

这篇关于表不可知的外键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆