0

I have two tables:
Country : has ID, Name
State : has ID, Name, CountryID

I defined Country.Name as unique.

I also want to define State.Name as unique per country - i.e. I can't just define it as unique because two countries may have the same state. But for one country, every state is unique.

How can I do this?

Bobby B
  • 2,287
  • 2
  • 24
  • 47

1 Answers1

1

Try to define UNIQUE for both columns Name and CountryID as below:

CREATE UNIQUE INDEX uix ON State( Name, CountryID)
Robert
  • 25,425
  • 8
  • 67
  • 81