在 sql 中创建属性主键和外键

Make attribute primary and foreign key in sql

如何在 table 开发人员中使用 sql 使属性成为 table 中的主键,同时作为引用另一个 table 的外键? 我知道如何使它成为一个属性作为外键和主键分开但不作为主键和外键

这很正常。例如:

create table employee (
  id number(6) primary key not null,
  name varchar2(50)
);

create table employee_desk (
  desk_id number(6) primary key not null, -- PK and FK!
  location varchar2(20),
  constraint fk1 foreign key (desk_id) references employee (id)
);

desk_id是tableemployee_desk的主键,也是指向tableemployee的外键。

下面是主键带外键的例子

 create table animals (id integer primary key);

  create table cats (
   id  integer   primary key
 , name varchar(100)  not null
 , constraint d_cats_animals_fk foreign key (id) references animals (id)
   );