在数据库中继承? [英] Inheritance in database?

查看:116
本文介绍了在数据库中继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在数据库中使用继承(特别是在SQL Server 2005中)?

Is there any way to use inheritance in database (Specifically in SQL Server 2005)?

假设我没有像 CreatedOn 这样的字段,我想在我的所有实体上添加 CreatedBy 。我正在寻找一种替代方法,而不是将这些字段添加到每个表中。

Suppose I have few field like CreatedOn, CreatedBy which I want to add on all of my entities. I looking for an alternative way instead of adding these fields to every table.

推荐答案

在表之间没有继承这样的东西SQL Server 2005,正如其他人所指出的那样,你可以获得在创建表时向表中添加必要的列的帮助,但它不会像你所知的那样继承。

There is no such thing as inheritance between tables in SQL Server 2005, and as noted by the others, you can get as far as getting help adding the necessary columns to the tables when you create them, but it won't be inheritance as you know it.

认为它更像是源代码文件的模板。

Think of it more like a template for your source code files.

正如GateKiller所提到的,你可以创建一个包含共享数据的表,用外键引用它,但你要么必须有审计挂钩,触发器,要么手动更新。

As GateKiller mentions, you can create a table containing the shared data and reference it with a foreign key, but you'll either have to have audit hooks, triggers, or do the update manually.

底线:手工工作。

这篇关于在数据库中继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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