Merhaba, yapmış olduğunuz şekilde primary key direk olarak stok kodu olması nedeniyle ve eşsiz olması nedeniyle tekrar aynı kodu kullanamıyorsunuz.
Bunun için Composite Primary Key kullanmalısınız.
Kısaca anlatmak gerekirse, Birden fazla attribute'un birleşmesi ile composite key oluşur. Sizin örneğinizde eğer primary key'i stok kodu ve siparis tarihi'ni kullanarak composite key oluşturursanız yaşadığınız problem ortadan kalkar.
Youtube konu anlatımı:
https://www.youtube.com/watch?v=OKJ5eoF-HqE
Hocam dediğiniz gibi yapıyorum fakat bu seferde stokapplied tablomda şu kodu çalıştırınca hata alıyorum...
KOD;
create table stokapplied --drop table stokapplied
(
UrunKodu bigint,
....
....
...
..
constraint UrunKodu foreign key references stokreceived(UrunKodu)
)
HATA;
Msg 1776, Level 16, State 0, Line 1
There are no primary or candidate keys in the referenced table 'stokreceived' that match the referencing column list in the foreign key 'UrunKodu'.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.