0

if I have tables like this:

GROUP(**GID**, DESC) -- GID IS PK    
USER(**UID**, FIRST, LAST, GID) -- UID IS PK, GID IS FK

A group can have multiple users but a user can belong to only one group.

How would I enforce rule so that an employee can belong only to one department?

Much appreciated

pixel
  • 9,653
  • 16
  • 82
  • 149

1 Answers1

2

With eid as a primary key you won't be able to insert more than one row for any employee as that would violate the primary key constraint. So there's no way an employee could ever belong to more than one department the way your tables are modeled.

jpw
  • 44,361
  • 6
  • 66
  • 86
  • Thanks jpw, sorry, I was using a wrong example. I updated the description above. But the way I see it still applies that PK is preventing a user from belonging to multiple groups. I see it now, thanks – pixel Jul 27 '15 at 23:53
  • 1
    @dbnex14 The example didn't really change anything. The primary key constraint still enforces that a user only can belong to one group . – jpw Jul 27 '15 at 23:57