关系数据库中的继承 [英] inheritance in relational database

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

问题描述

hi
How i implement inheritance in tables on a relational database?
for example i have the members class that is a super class and it has only user name attribute.my child classes are:admin_users and other_users that derived from members super class.these child classes consists of password attribute
for that user.i want to know each work must be done: implement this hierarchy in one table in database or each class must has own table.
thanks a lot.

推荐答案

不幸的是,我们仍然缺少真正的面向对象数据库,并且数据库仍然是关系型的。这就是为什么我们需要在应用程序和数据库之间进行数据库操作的对象关系映射器( ORM )。



但是,您可以在对象设计中实现数据库中的类似关系。也就是说,您可以拥有成员表,其中只有 {id,Name} 字段。然后,你可以拥有用户表,其中列 {MemberId} ,参考<$ c的Id字段$ c>成员表。 用户表还有另一列 UserType ,用于标识指向的用户类型(管理员用户或其他) user)另一个单独的表 UserType {Id,Type}
Unfortunately, we still lack a true Object Oriented database, and, databases are still Relational. That's why we need Object Relational mapper (ORM) between the application and the database to do database operations.

But, you can implement the similar relationship in the database, that you have in your object design. That is, you can have a Members table with only {id,Name} fields. Then, you can have User table with a column {MemberId}, referring to the Id field of the Members table. The User table will also have another column UserType for identifying the user type which points to (Admin user, or, other user) another separate table UserType{Id, Type}.


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

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