0

How can I make a multicolumn index for two columns where one of them can be null?

I only want the index to validate that there are no duplicates when both columns have value (when the nullable column is not null). When the nullable column is null I don't want the validation.

Is this possible?

4
  • Yes, CREATE UNIQUE INDEX u_name_of_index ON table_name (col1, col2); Commented Jan 5, 2022 at 11:08
  • Did you try this solution ? Commented Jan 5, 2022 at 11:15
  • @FrankHeikens :D this worked! I didn't think it would be that easy. Thank you! If you want to add it as an answer I will mark it as correct. Commented Jan 5, 2022 at 11:37
  • @Benoit thanks, did not since Frank's answer worked Commented Jan 5, 2022 at 11:38

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.