I'm making a foreign key but I don't understand why it won't work
Msg 1776, Level 16, State 0, Line 1 There are no primary or candidate keys in the referenced table 'dbo.QLKeSach' that match the referencing column list in the foreign key 'fk_QLKeSach_QLKeSach'. Msg 1750, Level 16, State 0, Line 1 Could not create constraint. See previous errors.
Like this:
create table QLKeSach
(
MaKeSach varchar(10) not null,
TenKeSach char(10) not null,
MaTang varchar(10) not null,
MaNgan varchar(10) not null,
MaKho varchar(10) not null,
)
create table QLTangSach
(
MaTang varchar(10) not null,
TenTang char(30) not null,
MaKeSach varchar(10) not null,
)
I created them but it gives an error
ALTER TABLE dbo.QLKeSach
ADD CONSTRAINT fk_QLKeSach
FOREIGN KEY (MaTang)
REFERENCES dbo.QLTangSach(MaTang);