is that possible to make foreign key from datetime datatype ? i try this but i got error message : Msg 1776, Level 16, State 0, Line 1 There are no primary or candidate keys in the referenced table 'penduduk' that match the referencing column list in the foreign key 'tgllahir'. Msg 1750, Level 16, State 0, Line 1 Could not create constraint. See previous errors.
i use this query
PARENT TABLE :
create table penduduk (
no int identity(1,1),
noktp char(11) primary key,
nama varchar(20),
tgl_lahir datetime NOT NULL,
namahari varchar(20),
tgl int,
bulan int,
namabulan varchar(20),
tahun int,
umur int
)
CREATE TABLE tua(
noktp CHAR(11) PRIMARY KEY,
tgl_lahir datetime NOT NULL CONSTRAINT tgllahir FOREIGN KEY REFERENCES penduduk(tgl_lahir),
FOREIGN KEY(noktp) REFERENCES penduduk(noktp),
)