July 10, 2003 at 8:09 am
"There are no primary or candidate keys in the referenced table ____ that match the referencing column list in the foreign key ___"
Does anyone know much about the error above? My main problem is that I'm trying to set a relationship (via FK) with two tables (it's a little more complicated than that but that's the basis). The primary key, made up of three fields, were made to be foreign keys in the other table, but I keep getting the message above.
Out of my ddl script I've cut and pasted the following example to my problem.
create table SAP_WBS (
SAP_WBS_ELEMENT varchar(24) not null,
SAP_COMPANY varchar(4) not null,
SAP_BUSINESS_AREA varchar(4) not null,
WBS_DESC varchar(47) null)
go
alter table SAP_WBS
add constraint SAP_WBS_PK primary key (SAP_WBS_ELEMENT, SAP_COMPANY, SAP_BUSINESS_AREA)
and then later on...
go
/* Update existing table dbo.DCD. */
alter table dbo.DCD add SAP_COMPANY_CODE varchar(4) null
go
alter table dbo.DCD add SAP_BUSINESS_AREA varchar(4) null
go
alter table dbo.DCD add SAP_GL_ACCOUNT varchar(10) null
go
alter table dbo.DCD add SAP_COST_CENTER varchar(10) null
go
alter table dbo.DCD add SAP_WBS_ELEMENT varchar(24) null
go
alter table dbo.DCD add SAP_INTERNAL_ORDER varchar(12) null
and finally...
alter table dbo.DCD
add constraint SAP_WBS_DCD_FK1 foreign key (
SAP_WBS_ELEMENT,
SAP_BUSINESS_AREA,
SAP_COMPANY_CODE)
references SAP_WBS (
SAP_WBS_ELEMENT,
SAP_BUSINESS_AREA,
SAP_COMPANY)
So mainly I have no idea why I'm getting this primary key type error??? The only thing I can think of is that I have 6 tables I'm relating back to the one table, DCD, and I'm receiving this error message on two of them - maybe it has to do with the relationships between the 6 tables?
July 10, 2003 at 12:35 pm
Must have been the length of the script that I had (I had other changes in the same script). I forgot that SQL Query Analyzer makes up it's own execution plan. When I split my script into two different scripts - one to update and the other to add FKs - I did not receive the error message.
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply