I have an application where users are granted access. Part of the system allows users to have their own 'clients'.
I have a users table
********************************
users
********************************
PK user_id int
username string
password string(salted)
********************************
and clients table
********************************
clients
********************************
PK client_id int
FK user_id int
username string
password string(salted)
********************************
What i want is that each user should be able to have a client with the same name. The case could be that two individuals choose to go with a different user, but by chance choose the same username. Therefore, there can be multiple entries for a username in the clients table, but against different user_ids.
The problem I have is that although the username field is not unique in the clients table, it should be unique for each user_id i.e. a user cannot have two or more clients with the same username.
How would I model this?