Inheritance in database?

后端 未结 9 1041
醉话见心
醉话见心 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:33

    in O-R mapping, inheritance maps to a parent table where the parent and child tables use the same identifier

    for example

    create table Object (
        Id int NOT NULL --primary key, auto-increment
        Name varchar(32)
    )
    create table SubObject (
        Id int NOT NULL  --primary key and also foreign key to Object
        Description varchar(32)
    )
    

    SubObject has a foreign-key relationship to Object. when you create a SubObject row, you must first create an Object row and use the Id in both rows

提交回复
热议问题