Implementing a “Both, Either-or, but Not Null” Requirement in a Database

后端 未结 4 1455
谎友^
谎友^ 2021-01-21 16:11

I have requirement for a web app that states that a user should be able to either upload an instruction document(s) (.pdf, .doc, .txt) or provide text for the instructions. The

4条回答
  •  礼貌的吻别
    2021-01-21 16:49

    Something feels a bit off here

    1. There is no UserID in this schema, so it should be added to the Instruction table.

    2. If a user does not upload anything, there will (should) be no entry for that user in the Instruction table.

    3. So the problem -- as stated -- is not about placing constraints on these three tables.

    4. When loading this structure, use a stored procedure and/or a transaction -- to make sure that at least one of the child record gets populated. Though, this has nothing to do with the business requirement that user has to upload something.

提交回复
热议问题