我有幾個表,例如:將同一個字段添加到多個表的最佳實踐是什麼?
news:
id | title | description
1 | This is first title of news | This is description
2 | This is second title of news | This is second description
blog:
id | title | description
1 | This is first title of blog | This is description
2 | This is second title of blog | This is second description
和另一多於10個表。
我需要添加一個字段「some_state」,它可以有兩個值:0或1
這樣我就可以通過兩種方式去:
1)添加該字段到每個表;
2)創建新表,例如:
tables_some_state:
id | table_name | table_id | some_state
1 | news | 1 | 0
2 | news | 2 |1
3 | blog | 1 | 1
4 | blog | 2 | 1
...
,並使用左加入此表的每個表在我的疑問。
那麼,我的情況是什麼樣的最佳做法?
一般來說*不好的做法是讓列中包含一個表名 - 當你考慮數據庫設計時,這應該會產生一個紅旗 – fspinnenhirn
這只是一個例子。我的表格字段設置更復雜。我使用2個字段,而不是字段「table_name」,例如「組件」和「元素」,就像那樣。 – webprogrammer