是否可以从日期时间数据类型制作外键?我尝试了这个,但我收到了错误消息:Msg 1776,Level 16,State 0,Line 1 引用表 'penduduk' 中没有与外键 'tgllahir' 中的引用列列表匹配的主键或候选键。消息 1750,级别 16,状态 0,行 1 无法创建约束。请参阅以前的错误。
我使用这个查询
父表:
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),
)