我只是有一个关于符号的快速问题。我现在有两张 table 。
这个有基本的动物信息:
create table d_animals (
an_id integer primary key
, an_gender varchar2(1) not null
, an_dob date not null
, an_name varchar2(10) not null
);
这是关于猫的:
create table d_cats (
an_id integer primary key
, feline_leukemia_test_date date not null
, an_id foreign key references d_animals_(an_id)
);
如您所见,我尝试将 an_id 用作 d_cats 中的主键,但也引用 d_animals 表中的 an_id。我收到 d_cats 的以下错误:
ORA-00957: duplicate column name
那么我该如何正确地写这个呢?
另外,我不想为 d_cats 创建另一列。我的教授希望我们只用 an_id 和 feline_leukemia_test_Date 编写 d_cats。
谢谢。
最佳答案
使用命名约束,即:
create table d_cats (
an_id integer primary key
, feline_leukemia_test_date date not null
, constraint d_cats_animals_fk foreign key (an_id) references d_animals (an_id)
);
关于sql - Oracle Sql : foreign-key is also primary key syntax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13576553/