2013-01-17 59 views
0

我想有兩個表:數據庫表造型 - 列繼承

[Table1]   [Table2] 
id1    id2 
createdon  createdon 
createdby  createdby 
column1a   column2 
column1b     

可以看到,這兩個表做有「createdon」和「createdby」列。類似的事情與我的其他桌子。有沒有一種方法來建模和實現數據庫表結構的列繼承(就像我會用OOP中的類屬性做的那樣)。從概念上講我的意思:我想創建一個超霸表:

[Supertable] 
createdon 
createdby 

並做出表10和Table20延長超表。這樣我就不必爲每個特定的表創建'createdon'和'createdby'列,因爲它們將從超級表繼承。

[Table10] extends [Supertable] results in wanted [Table1] 
id1     createdon       id1 
column1a   createdby       createdon 
column1b            createdby 
                 column1a 
                 column1b 

[Table20] extends [Supertable] results in wanted [Table2] 
id2     createdon       id2 
column2    createdby       createdon 
                 createdby 
                 column2 

所以表10,Table20和Supertabe只是內部RDBMS和Table 1和表2的結構是什麼數據庫用戶看到的決賽桌,當他們訪問數據庫。在MySQL(或任何其他RDBMS)中是否可能這樣?

+1

Postgres支持表繼承。 MySQL不。 –

回答

0

從純粹的建模角度來看......爲什麼不可能呢?然後

你的表結構是這樣的(我已經適應你的語法):

[Table1]  [Table2] 
id1   id2 
column1a  column2 
column1b 

......還有......

[Table0] 
table <- either Table1 or Table2 
id  <- either the value id1 or id2 
createdon 
createdby 

但最大的問題是...你會在你的申請中受益嗎?如果不仔細觀察你將要做的事情,我就不能回答這個問題。

+0

也許我在我的問題中是missundersood,或者我不明白你的答案,所以我重新提出了我的問題。 – sbrbot

+0

請不要誤解ORDBMS中的RDBMS。你想要實現的是可能的,但不是通過真正的「擴展」表的方式,就像你可能習慣ORDBMS一樣。 – Bjoern

0

您還可以與關聯鍵鏈接在一起的表:

[supertable] 
id 
createdon 
createdby 

[Table1] 
id1 
supertable_id  
column1a  
column1b  

這不是你在尋找什麼,但可能是有用的。

+0

這不是我的意思,但無論如何感謝。 – sbrbot