Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inheritance in database?

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

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.

like image 748
Ramesh Soni Avatar asked Aug 08 '08 10:08

Ramesh Soni


People also ask

What is inheritance in DBMS with example?

Inheritance is an important feature of Generalization and Specialization. It allows lower-level entities to inherit the attributes of higher-level entities. For example, the attributes of a Person class such as name, age, and gender can be inherited by lower-level entities such as Student or Teacher.

What is inheritance in SQL?

SQL object inheritance is based on a family tree of object types that forms a type hierarchy. The type hierarchy consists of a parent object type, called a supertype, and one or more levels of child object types, called subtypes, which are derived from the parent.

What data model uses inheritance?

In this article. The Entity Data Model (EDM) supports inheritance for entity types. Inheritance in the EDM is similar to inheritance for classes in object-oriented programming languages.

What is polymorphism in database?

Polymorphism. Polymorphism is the capability of an object to take multiple forms. This ability allows the same program code to work with different data types.


1 Answers

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.

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.

Bottom line: Manual work.

like image 98
Lasse V. Karlsen Avatar answered Sep 23 '22 02:09

Lasse V. Karlsen