Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 fields combination unique in table...

Status
Not open for further replies.

strucnjak79

Programmer
Oct 14, 2005
37
BA
So I need two unique fields in my table, but they should not be unique separately, just a combination of values in this two fields... Let's say I have table with fields book, page, text... I can have more then one book #1, more than one pages #1 but only one combination of book #1 and page #1! But I have page #1 for each book!

How to restrict this in MySQL?
 
Declare a unique index on the combination of the two fields:
[tt]
ALTER TABLE tblname
ADD UNIQUE INDEX bookpageindex (bookfield,pagefield)
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top