我认为 PK 应该只是 EmployeeID,因为它应该始终是唯一的。我的同事认为 PK 应该与 StoreID+EmployeeID 复合,但是(理论上)可能会有重复的员工 ID。
你说的是两件略有不同的事情。
如果你只想识别员工,那么主键可能应该是employee_id,并且商店的id号根本不应该在那个表中。但是,另外,如果您想知道员工通常在哪个商店工作,您可以将 store_id 包含在 employees 表中(并使其成为NOT NULL
),或者您可以创建一个单独的表。
In the 25+ years I've been doing this stuff, I've often had people tell me that an employee can work at only one store. That's almost always untrue, often even at the moment the managers are swearing it is true. One time, we were "discussing" this in a room with half a dozen employees who all worked at more than one store. One of them worked at five different stores every week. And all the managers knew this. When we pointed out all the people who worked at more than one store, the managers still insisted that everyone worked at only one store. (shrug)
I favor using a separate table to store employees current, paid work locations. The main reason is that management always want more information about that relationship besides just that bare fact. Always. Attendance, timekeeping, always something else.
In that table, you'll need a composite primary key of at least {store_id, employee_id}. You might need more columns (and sometimes more tables) than that, depending on what other information you want to store about that location relationship. You'll also need some kind of administrative procedure (which you might or might not be able to automate) to make sure every employee has at least one current, paid work location. (If you dbms ever supports assertions, you can get rid of the administrative procedure.)