PDA

View Full Version : primary key?


Bengal313
01-15-2003, 07:11 PM
I have a table with the following fields.
Streetname
houseno
aptno
owner
homephone
workphone
zip

I want to be able to create a primary key using a combination of fields (streetname, houseno, and aptno) is that possible and how would I do that using phpmyadmin? Please help?

Kiwi
01-15-2003, 07:55 PM
mySql doesn't support composite keys or indexes. You can mimic the behaviour at the application level. To do this, you need to add an auto-increment primary key -- you will probably never refer to this. When you add or update any fields in that table, you need to check that the composite field is unique.

This is exactly how a real database implements composite keys -- the difference is the database does the work (and enforces the rules) instead of the application. You cannot, unfortunately, have composite indexes. However, indexing each of the fields in your key independently combined with mySql's look-up speed gives you similar performance.