Reputation: 1604
I have created 1 table which stores the user
and uid
.
Other table stores the skills of the user:
uid = 111
enters skill = aaa
it will stored to the skill table but I want when uid = 111
again enters the skill = aaa
it should not store in skill table. uid = 222
enters skill = aaa
then table will store the value. Basically I want to relate uid
and skill fields of skill table so on every unique uid
there should be unique skill values, but for different uid
s skill can be same.
Upvotes: 0
Views: 494
Reputation: 79929
Use a composite primary key on the two ids UId
and skill. Also, to make it many to many relation between the two tables, so that each user has many skills, and to normalize your tables, better off create it this way:
Users
table:
UserID
Primary key,USername
.Skills
table:
SkillId
Primary key,SkillName
,The linkage table:
UsersSkills
:
UserId
Foreign key references Users(UserId)
,SkillId
Foreign key references Skills(SkillId)
.And then the important part is to make a composite primary key on UserId
and SkillId
, so that the skill is unique for each userid.
In your example, the skill aaa
would be stored in the Skills
table with an Id = 1, where the user UserId = 111
is stored in the Users
table. Then the UsersSkills
will contain something like:
UserId SkillId
111 1
Upvotes: 1