I've been trying to solve this error for several minutes but I don't know what am I missing from table definition.
The code for the tables are below:
Table Autocare
:
CREATE TABLE [dbo].[Autocare]
(
[IDAutocar] NUMERIC (18, 0) NOT NULL,
[IDTipAutocar] NUMERIC (18, 0) NOT NULL,
PRIMARY KEY CLUSTERED ([IDAutocar] ASC, [IDTipAutocar] ASC),
CONSTRAINT [FK_Autogari_TipAutocar]
FOREIGN KEY ([IDTipAutocar])
REFERENCES [dbo].[TipAutocar] ([IDTipAutocar])
);
Table Curse
:
CREATE TABLE [dbo].[Curse]
(
[IDCursa] NUMERIC (18, 0) NOT NULL PRIMARY KEY,
[IDTraseu] NUMERIC (18, 0) NOT NULL,
[Data] TIMESTAMP NOT NULL,
[IDCompanie] NUMERIC (18, 0) NOT NULL,
[NrLocuri] NUMERIC (18, 0) NOT NULL,
[IDAutocar] NUMERIC (18, 0) NOT NULL,
CONSTRAINT [FK_Curse_Trasee]
FOREIGN KEY ([IDTraseu])
REFERENCES [Trasee]([IDTraseu]),
CONSTRAINT [FK_Curse_Companii]
FOREIGN KEY ([IDCompanie])
REFERENCES [Companii]([IDCompanie]),
CONSTRAINT [FK_Curse_Autocare]
FOREIGN KEY ([IDAutocar])
REFERENCES [Autocare]([IDAutocar])
)
When I try to execute the second script I get the following error (and I know is something related to the relationship between tables) and I don't figure out where the problem might be. I'm a newbie into C# and SQL Server, so please forgive if I asked a stupid question.
Msg 1776, Level 16, State 0, Line 1
There are no primary or candidate keys in the referenced table 'Autocare' that match the referencing column list in the foreign key 'FK_Curse_Autocare'.Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.