Inheritance in database?

后端 未结 9 1036
醉话见心
醉话见心 2021-01-11 20:14

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

Suppose I have few field like CreatedOn, CreatedBy

相关标签:
9条回答
  • 2021-01-11 20:47

    If you are using GUIDs you could create a CreateHistory table with columns GUID, CreatedOn, CreatedBy. For populating the table you would still have to create a trigger for every table or handle it in the application logic.

    0 讨论(0)
  • 2021-01-11 20:47

    Ramesh - I would implement this using supertype and subtype relationships in my E-R model. There are a few different physical options you have of implementing the relationships as well.

    0 讨论(0)
  • 2021-01-11 20:48

    You do NOT want to use inheritance to do this! When table B, C and D inherits from table A, that means that querying table A will give you records from B, C and D. Now consider...

    DELETE FROM a;

    Instead of inheritance, use LIKE instead...

    CREATE TABLE blah (
        blah_id     serial       PRIMARY KEY
        , something text         NOT NULL
        , LIKE template_table    INCLUDING DEFALUTS
    );
    
    0 讨论(0)
提交回复
热议问题