[英]Can we use constraint name of a primary key as foreign key reference?
For example, I'm creating two tables as shown below:例如,我正在创建两个表,如下所示:
create table A (
department_id int,
college_id int,
constraint Pk_name primary key(department_id,college_id)
);
create table B (
student_name varchar(75),
department_id int,
college_id int,
foreign key(department_id,college_id) references A(Pk_name)
);
Can I write like this?我可以这样写吗?
I don't think so because there's no way that the RDBMS could know whether PK_name
is a column or a constraint name so I suggest if you stick with the usual:我不这么认为,因为 RDBMS 无法知道PK_name
是列名称还是约束名称,所以我建议您是否坚持通常的做法:
create table A ( department_id int, college_id int, constraint Pk_name primary key(department_id,college_id) );
create table B ( student_name varchar(75), department_id int, college_id int, foreign key(department_id,college_id) references A(department_id,college_id) );
I will update the answer once I find an other answer.一旦找到其他答案,我将更新答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.