Problems creating relationships in SQL SMS

Zedster

Registered User.
Local time
Today, 13:24
Joined
Jul 2, 2019
Messages
169
I am trying to create a relationship between two tables in server management studio using the relationships dialog box.

The master table tblMeetings has a primary key "M_ID" of datatype varchar(10). The child table tblStandardMeetingInvitees also has a field "M_ID" of datatype varchar(10) intended to be the foreign key.

The relationships dialog box allows me to set up the relationship fine. But when I go to save I keep getting the following error:

'tblMeetings' table saved successfully
'tblStandardMeetingInvitees' table
- Unable to create relationship 'FK_tblStandardMeetingInvitees_tblMeetings'.
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_tblStandardMeetingInvitees_tblMeetings". The conflict occurred in database "Meetings", table "dbo.tblMeetings", column 'M_ID'.


I am a little confused and would appreciate any advice.
 
The fields are:

tblStandardMeetingInvitees (child table)

SMI_ID varchar(10) Unchecked Keyfield
M_ID varchar(10) Unchecked
MD_Category varchar(20) Checked
SMI_Person varchar(50) Unchecked
SMI_Email varchar(100) Checked
timestamp timestamp Checked

tblMeetings (parent table)

M_ID varchar(10) Unchecked Keyfield
M_Description varchar(50) Unchecked
M_Objective varchar(MAX) Checked
M_Frequency varchar(50) Checked
M_Comments varchar(MAX) Checked
timestamp timestamp Checked
 
Your intended FK probably has values that are not in your PK column

Code:
select * from  tblStandardMeetingInvitees where M_ID not in ( Select M_ID from tblMeetings)

Should list your problematic records
 
Your intended FK probably has values that are not in your PK column

Code:
select * from  tblStandardMeetingInvitees where M_ID not in ( Select M_ID from tblMeetings)

Should list your problematic records
Well done, I designed the database structure quite a while ago and then it got mothballed. I thought all the tables were empty and never even thought to look. But on inspection there are three entries in tblStandardMeetingInvitees but the tblMeetings has no records, hence the error.

All good now.

Thanks
 

Users who are viewing this thread

Back
Top Bottom