Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Require help in creating table Expand / Collapse
Author
Message
Posted Thursday, October 17, 2013 10:37 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Sunday, October 20, 2013 11:09 PM
Points: 15, Visits: 34
I am having a main table - Client (ClientID Primary Key)

Then 2 tables below:

1. Employee (EmployeeID Primary Key, with ClientID as Foreign Key)
2. User (UserID Primary Key)

Now, it is possible that one employee might be working for more than one client. So, the EmployeeID/EmpCode/Paycode (many other data) will be different for a single person per client. Question is: User should only be able to use ONE user to access both client information. In other words, there should only be ONE user created in the system to access clients for whom employee is working.

Example: "ABC" is a taxi driver (Employee). He is working for "XYZ" and "PQR" (Clients).

1. Client Table:
ClientName: XYZ, ClientID: 1, ...
ClientName: PQR, ClientID: 2, ...
2. Employee Table:
EmpName: ABC, EmpCode: 679, ClientID: 1, Shift: Day, ...
EmpName: ABC, EmpCode: 579, ClientID: 2, Shift: Night, ...
3. User Table:
UserID: 100, UserName: ABC_User

Somehow, I need to normalize the "User" "Employee" table in a way that with only "ABC_User" user login, "ABC" should be able to access data for Client "XYZ" and "PQR". I thought of creating a table "UserAccess" with ClientID, EmployeeID and UserID.

Let me know your thoughts.
Post #1505972
Posted Friday, October 18, 2013 4:16 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Today @ 4:40 AM
Points: 58, Visits: 310
first question is
do employee for example BBB should have access to "XYZ" and "PQR"?
Post #1506063
Posted Friday, October 18, 2013 4:40 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Sunday, October 20, 2013 11:09 PM
Points: 15, Visits: 34
Yes it is possible. Thinking of it in this way:
"BBB" is actually employee (project manager) of client "XYZ", but he is also working as employee (as consultant) for client "PQR".
Post #1506068
Posted Saturday, October 19, 2013 6:32 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 4:56 PM
Points: 8,271, Visits: 8,717
The schema definition seems odd. You might find that things become easier if you change the definition of the Employee table to be something like

Employee (user_id not null references User(UserID), ClientID not null references Client(ClientID), ...other attributes..., primary key (UserID,ClientID))

so that the Employee table (which is a table where each row shows the relationship between a client and a user, not a table describing an entity) has the compound primary key required to indicate the client and user for which the row with that primary key describes the relationship. That will eliminate the dummy entity identifier EmployeeID, which you can't use as a primary key despite the statement in your first post that it is the primary key because it's not unique: the data in your post has two rows with the same value for that column, and which is in any case clearly being used to say which user is involved, not which Employee relationship.


Tom
Post #1506392
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse