sql - pointing foreign key to datetime -


is possible make foreign key datetime datatype ? try got error message : msg 1776, level 16, state 0, line 1 there no primary or candidate keys in referenced table 'penduduk' match referencing column list in foreign key 'tgllahir'. msg 1750, level 16, state 0, line 1 not create constraint. see previous errors.

i use 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), ) 

try this:

create table penduduk ( no int identity(1,1), noktp char(11) primary key, nama varchar(20), tgl_lahir datetime not null unique, 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), ) 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -