StuartBombay
Programmer
I'm not sure what this is doing, but I'm guessing that it is checking the user table to make sure the ID (guid) exists in the user table before adding it to the user_group table?
This constraint exists on the user table:
I'm confused because I get this error when I try to insert into the user_group table. I'm *sure* the users exists in the user table:
The INSERT statement conflicted with the FOREIGN KEY constraint "fkey$user_group$uguser". The conflict occurred in database "Touchy", table "user", column 'guid'.
There is a user table and a group table. The user_group table defines which group(s) the users belong to. Belonging to more than one group is allowed.
Here is the code for the insert, it's taking the data from a temp table:
Thanks for any help you can offer with this, maybe it's not the constraint that's causing the problem but rather the insert part?
This constraint exists on the user table:
Code:
ALTER TABLE [user_group] WITH CHECK ADD
CONSTRAINT [fkey$user_group$uguser]
FOREIGN KEY([user_id])
REFERENCES [user] ([guid])
I'm confused because I get this error when I try to insert into the user_group table. I'm *sure* the users exists in the user table:
The INSERT statement conflicted with the FOREIGN KEY constraint "fkey$user_group$uguser". The conflict occurred in database "Touchy", table "user", column 'guid'.
There is a user table and a group table. The user_group table defines which group(s) the users belong to. Belonging to more than one group is allowed.
Here is the code for the insert, it's taking the data from a temp table:
Code:
INSERT INTO user_group
(
user_id,
group_id,
tps_receive_group_messages,
tps_membership_type,
tps_creation_user_guid,
tps_creation_date,
tps_last_update_user_guid,
tps_last_update
)
SELECT tpUserGuid, tpGroupGuid, a, b, cu, cdt, uu, udt
FROM NewUserGroups s
WHERE not exists (select user_id, group_id
FROM user_group d
WHERE d.user_id = s.UserGuid AND d.group_id = s.GroupGuid)
Thanks for any help you can offer with this, maybe it's not the constraint that's causing the problem but rather the insert part?