Can the same column have primary key & foreign key constraint to another column

后端 未结 3 1073
执笔经年
执笔经年 2021-01-07 19:13

Can the same column have primary key & foreign key constraint to another column?

Table1: ID - Primary column, foreign key constraint for Table2 ID
Table2         


        
3条回答
  •  盖世英雄少女心
    2021-01-07 20:12

    Assigning Primary Key And Foreign key to the same column in a Table:

    create table a1 (
        id1 int not null primary key 
    );
    insert into a1 values(1),(2),(3),(4);
    
    create table a2 (
        id1 int not null primary key foreign key references a1(id1)
    );
    insert into a2 values(1),(2),(3);
    

提交回复
热议问题