Ad

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.

Ad

Answer

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.

Ad
source: stackoverflow.com
Ad