I have two tables, Positions and Users:
Users
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](100) NULL,
[DOB] [varchar](10) NULL,
[PositionId] [int] NULL
Positions
[Id] [int] IDENTITY(1,1) NOT NULL,
[PosName] [varchar](100) NULL,
[PosDesc] [varchar](10) NULL,
[UserId] [int] NULL
In these tables, Users.PositionId is a foreign key to Positions.Id. Positions.UserId is a foreign key to Users.Id.
In my database, a user can exist without having a position and a position does not need to be assigned to a user. HOWEVER, if a user is assigned to a position in the user's table, then I also want that position to be assigned to the user in the position's table. What I want to avoid is having User A assigned to Position B, when in turn Position B is assigned to User X.
Is there any way I can have SQL Server update the foreign key of Table B with the primary key of Table A whenever I update the foreign key on Table A (and vice-versa)?
I know that we can do cascades with foreign keys (ON DELETE, ON UPDATE, etc.). However, I don't think there is an application with this for what I want to do. The only other thing I could think of was using a database trigger, but is that really the most effective way to handle this??? I have seen a TON of topics on stack overflow about tables with foreign keys referencing each other, but I can't seem to quite find anything regarding my specific issue.
I appreciate any help on this matter!