3

If i create a unique constraint like this unique(colA, colB);

Does it create 2 indexes, 1 for each column? Or how does it actually work internally?

2
  • 1
    what do you mean whit "work internally" ?? .. anyway the each unique constraint require an proper index .. Commented Jan 7, 2021 at 17:15
  • 2
    Mandatory reading about indexes: use-the-index-luke.com Commented Jan 7, 2021 at 17:20

1 Answer 1

2

It will create only one index on two columns and both the column combinedly can not contain duplicate in the entire table.

You can add multiple duplicates for colA but considering that the colB is different for each row having same colA and vice-versa.

colA colB Tejash SO Tejash SO1 Tejash SO2 

Allowed

or

colA colB SO1 TEJASH SO2 TEJASH SO3 TEJASH 

is also allowed.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I query colA a lot, so i have to explicitly creat another index on colA create index on table(colA); Is that right?
No. Of you query colA then your existing index will be used as its position in index is 1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.