I am currently working on an application where I have 2 Tables. User and Team. User has UserId as PK and UserPassword.
Team table has TeamId as PK and TeamName.
Originally I had one single table where I had UserId, UserPassword and TeamId but it was pointed out to me that the current design is not normalized. Hence I had to break the table into User, Team and also a Join Table named User_Team which contains UserId as PK from User table and TeamId as PK from Team table.
Constraints One User can be in only 1 team and 1 team can have many users.
So as per my understanding, it is a OneToMany from Team to User side.
I have made UserId and TeamId together as a composite key and also made it unique in the JoinTable(User_Team) so that 1 user cannot be in multiple teams.
My query is that is it necessary to break the table into Team table seperately. Cant I just have all 3 fields in one single table. Can someone explain me how it is not normalized. Also let me know if there is a need of JoinTable in this case.
No, you do not need a JoinTable for a OneToMany relation. Just have a teamId
field on your User table and you're good to go.
As a rule of thumb:
User
for your case) has a foreign key