How do I apply subtypes into an SQL Server database?

前端 未结 5 936
孤独总比滥情好
孤独总比滥情好 2020-12-28 20:05

I am working on a program in which you can register complaints. There are three types of complaints: internal (errors from employees), external (er

5条回答
  •  猫巷女王i
    2020-12-28 20:44

    In response to you're comment on the accepted answer:

    Below is a way to have a check check to ensure only one of the three keys has data:

    alter table complaint_master 
        add constraint loc_attribute_has_one_value 
        check ( 
            (case when complaint_employee is null then 0 else 1 end) + 
            (case when complaint_supplier is null then 0 else 1 end) + 
            (case when complaint_external is null then 0 else 1 end)  = 1 
        ); 
    

提交回复
热议问题