I've trawled the internet trying to find an answer for this - I should preface this question with my being a total amateur.
EDIT: The Database type is mySQL
EDIT: The band sizes aren't dynamic; they're for showbands ie a 5 piece will always be Vocals | Guitar | Keys | Bass | Drums
EDIT: I've included some sample data at the bottom
So, the problem is thus:
I have a table of musicians (musiciansID)
I have a table roles (rolesID), which is their role in a band (vocals, guitar etc)
I have a table of musicians_roles (musiciansID, rolesID). Musicians can play many instruments.
I have a table of specific bands (bandID) (8 piece, 6 piece) etc
I have a table of band_roles (bandID, rolesID).
Each band has a specific format eg 3 piece | Vocals, Guitar, Drums
I'm banging my head against the wall trying to enforce something like the following:
BandID = 1 (3 piece, say)
BandID has RolesID = 1,2,3 (Vocals, Bass, Drums)
and this is the bit where I fall down
BandID has MusiciansID = 1,2,3 (John, Paul, Ringo), but I'd like the constraint to fail if I tried to put Ringo as the bass player for example.
I'm SO sorry if this is super simple and I just don't have the vocabulary to search for it. I have a feeling the answer may be something similar to the link below, but I can't get it to work.
https://dba.stackexchange.com/questions/34040/many-to-many-and-weak-entities
Some sample data
Musicians:
Joe Bloggs
Sarah Samsonite
Sam Stalactite
Don Bike
Tracy Shiney
Roles:
Vocals
Trumpet
Saxophone
Guitar
Bass
Drums
Keyboards
Musicians_roles:
Joe Bloggs, Saxophone
Joe Bloggs, Drums
Sarah Samsonite, Vocals
Sam Stalactite, Drums
Don Bike, Guitar
Tracy Shiney, Bass
Band_Roles:
5 piece, Vocals
5 piece, Keyboards
5 piece, Guitar
5 piece, Drums
5 piece, Bass
6 piece, Vocals
6 piece, Keyboards
6 piece, Guitar
6 piece, Drums
6 piece, Bass
6 piece, Sax
Musicians in band:
5 piece, Vocals, Sarah Samsonite
5 piece, Keyboards, NULL
5 piece, Guitar, NULL
5 piece, Drums, Sam Stalactite
5 piece, Bass, NULL
Then, say for example I tried to put Sarah Shiney on guitar, it would fail.
Thank you so much for your time!