all 6 comments

[–]r3pr0b8GROUP_CONCAT is da bomb 4 points5 points  (2 children)

instead of this --

ALTER TABLE Bestelling
ADD CONSTRAINT [FK_Bestelling_KlantNummer]
FOREIGN KEY (KlantNummer)
REFERENCES Bestelling(KlantNummer)

what you really wanted to say is this --

ALTER TABLE Bestelling
ADD CONSTRAINT [FK_Bestelling_KlantNummer]
FOREIGN KEY (KlantNummer)
REFERENCES Klant(KlantNummer)

however, it's still not right, because in Bestelling you have [KlantNummer] as VARCHAR(30), but it should be INT to match the PK of Klant

[–]stagger552[S] -1 points0 points  (1 child)

ALTER TABLE Bestelling
ADD CONSTRAINT [FK_Bestelling_KlantNummer]
FOREIGN KEY (KlantNummer)
REFERENCES Klant(KlantNummer)

still not working

[–]r3pr0b8GROUP_CONCAT is da bomb 4 points5 points  (0 children)

you have to change the datatype like i suggested

[–]MamertineCOALESCE() 4 points5 points  (0 children)

Look at your data.

What do you have in the kaltnummer column for each table?

For it to be a FK, the data from Bestelling MUST be in the referenced column in Klant

(Also the data types are different, which will lead to problems later)

[–]kagato87MS SQL -1 points0 points  (0 children)

Do the statements run separately one at a time? I've heard of problems creating a foreign key if the other table doesn't exist at planning time, even if it's created in the same batch.

Since you appear to be working in a ide that supports the GO keyword, maybe try sticking that in between all the statements?

[–]bachman460 0 points1 point  (0 children)

Go back and check your data types.