How to enforce a constraint in a table already created?

╄→гoц情女王★ 提交于 2019-12-12 06:57:44

问题


I am trying to figure out the correct constraint syntax for the following statement:

"For a given measurement, when Value is present, the Outlier Indicator must be NULL (and, conversely, the Value must be NULL if the Outlier Indicator is present).

'Value' and 'Outlier Indicator' are two columns that I have in a table.

What I have been doing so far is

  1. Right Click on table name in the left pane to open "Edit Table"
  2. Click "Edit"
  3. Click on "Constraints" in the left pane
  4. Click on the Green Plus > "New Check Constraint"

What this does open up a new text section in the "Edit Table" box called "Check Condition" where I have to specify the constraint in a syntax that Oracle SQL Developer can understand.

This method has worked so far with other constraints that I have enforced but for some reason I cannot figure out how to word this particular one.

Any help will be appreciated, thanks.

This is all happening in Oracle SQL Developer, btw.


回答1:


You would do this in code as;

alter t add constraint chk_t_cols
    check ( (Value is null and outlier is not null) or (value is not null and outlier is null) )

The part after the check is what you would type in the box in the GUI.



来源:https://stackoverflow.com/questions/44060363/how-to-enforce-a-constraint-in-a-table-already-created

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!