TysonLPrice
Programmer
I’m a programmer with just a smattering of SQL database background which is mainly accessing the predesigned databases. I’m changing an application which involves adding a new table and relationship. It’s basically this: There is a single table in currently in place that contains information about users such as departments login information, certain privileges, etc. There is only one entry per user. I’m only interested in three columns at this point.
CurrentTable
UserID Company Department
User1 fkCompany fkDepartment
User2 fkCompany fkDepartment
User3 fkCompany fkDepartment
The requirement is that for one process the user can be in multiple companies and departments for a certain function. What I have in place in test is a table like this:
NewTable
UserID Company Department
User1 fkCompany fkDepartment
User1 fkCompany fkDepartment
User2 fkCompany fkDepartment
User2 fkCompany fkDepartment
User2 fkCompany fkDepartment
User3 fkCompany fkDepartment
User3 fkCompany fkDepartment
The logic in the program is:
Select UserID, fkCompany, fkDepartment, 1 ‘Source’ from CurrentTable
Where UserID = ‘XXX’
Union
Select UserID, fkCompany, fkDepartment, 0 ‘Source’ from NewTable
Where UserID = ‘XXX’
Order by Source Desc -- Keeps the primary Company and Department first in the returned rows
I’ll need to set up a maintenance screen for the new table.
Someone mentioned I should be creating a join/junction table for this. I’ve looked on-line at the concept but I don’t see why I need one. I’d like some feedback on this before I go much further since it is a new process. The CurrentTable is used extensively, always expects one row per user, and changing it is not an option.
CurrentTable
UserID Company Department
User1 fkCompany fkDepartment
User2 fkCompany fkDepartment
User3 fkCompany fkDepartment
The requirement is that for one process the user can be in multiple companies and departments for a certain function. What I have in place in test is a table like this:
NewTable
UserID Company Department
User1 fkCompany fkDepartment
User1 fkCompany fkDepartment
User2 fkCompany fkDepartment
User2 fkCompany fkDepartment
User2 fkCompany fkDepartment
User3 fkCompany fkDepartment
User3 fkCompany fkDepartment
The logic in the program is:
Select UserID, fkCompany, fkDepartment, 1 ‘Source’ from CurrentTable
Where UserID = ‘XXX’
Union
Select UserID, fkCompany, fkDepartment, 0 ‘Source’ from NewTable
Where UserID = ‘XXX’
Order by Source Desc -- Keeps the primary Company and Department first in the returned rows
I’ll need to set up a maintenance screen for the new table.
Someone mentioned I should be creating a join/junction table for this. I’ve looked on-line at the concept but I don’t see why I need one. I’d like some feedback on this before I go much further since it is a new process. The CurrentTable is used extensively, always expects one row per user, and changing it is not an option.