同一列是否可以对另一列有主键和外键约束?
Table1: ID - Primary column, foreign key constraint for Table2 ID
Table2: ID - Primary column, Name
如果我尝试删除 table1 数据,这会成为问题吗?
Delete from table1 where ID=1000;
谢谢。
最佳答案
将主键和外键分配给表中的同一列:
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);
关于sql - 同一列可以对另一列有主键和外键约束吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3774923/