Skip to content
Advertisement

conditional primary key based on value not being null

I have a table that has a composite primary key:

The problem is that when I insert into this table, the data from the product_home column is null for the rows where product_home_ods has data. The same applies product_home_ods, the rows where that table contain data are null for product_home.

Example:

Is it possible to create a primary key based on the condition of these columns ? I understand a primary key should not contain null values, but unsure about the best way to tackle this problem.

Advertisement

Answer

And changing to this model ? product_home will never be NULL and ods_flag will indicate if it should be interpreted a product_home or product_home_ods, something you can do in a view to get back the same data as your original table.

(As long as product_home and product_home_ods of your original table are not foreign keys)

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement