weblab-tw / ddia-study-group

Designing Data-Intensive Applications Study Group
36 stars 4 forks source link

第七章:Write Skew 可使用的 Constaint - Parker #81

Open Parkerhiphop opened 1 year ago

Parkerhiphop commented 1 year ago

在 Write Skews (寫偏差) 中有提到 可使用 Constraint(約束)來解: 某些資料庫允許配置約束,然後由資料庫強制執行(例如,唯一性,外來鍵約束或特定值限制)。但是為了指定至少有一名醫生必須線上,需要一個涉及多個物件的約束。大多數資料庫沒有內建對這種約束的支援,但是你可以使用觸發器,或者物化檢視來實現它們,這取決於不同的資料庫。

對於如何使用約束還不是很清楚,但感覺這種情況挺常見的,想請問有人設置過 Constraint 嗎?

參考資料:

  1. 文中是用 Oracle:https://tonyandrews.blogspot.com/2004/10/enforcing-complex-constraints-in.html
  2. SQL Server 也有:https://docs.microsoft.com/zh-tw/sql/relational-databases/tables/unique-constraints-and-check-constraints?view=sql-server-ver16
at7211 commented 1 year ago

就是加 foreign key 或是設定 unique 等 可以參考:https://pjchender.dev/database/sql-table-manipulate/#more-about-constraint

jxiu0129 commented 1 year ago