I want to create a table structure like this in MySQL:
id | area | name
----+----------+------------
1 | name-1 | test
| |
1 | name-1 | value2
| |
2 | name-2 | test-value
| |
3 | name-3 | test
| |
3 | name-3 | test
ie. the primary key will be: primary_key( id, area ) and the id will be auto_increment, but i only want the id to increment for every new unique area
is this possible?
What you want is not possible. You want
idandareato be the primary key but in your example they are not unique.If you define a table key it must be unique and in your example that would mean you need to include
namein your primary key. But why not make justidthe primary key and auto-increment it? That is the common usage.EDIT :
You could create an extra field called
area_idfor instance. You can add the auto-increment functionality to the field likE this: