[英]insertion constraint by Foreign key due to referencing same table
I have a table employee which has ssn as primary key and another supr_ssn attribute which is a foreign key referencing ssn of employee table itself. 我有一个表ssn作为主键的雇员表,另一个supr_ssn属性是一个引用雇员表本身的ssn的外键。 So while inserting into table I get foreign key constraint because I have not inserted any value into ssn . 因此,在插入表时,我得到了外键约束,因为我没有在ssn中插入任何值。 Here is my table: 这是我的桌子:
create table employee(
Fname varchar(15) not null,
Minit char,
Lname Varchar(15) not null,
ssn char(9) not null,
Bdate Date,
Address varchar(30),
sex char,
Salary decimal(10,2),
super_ssn char(9),
Dno int not null,
primary key(ssn),
foreign key(super_ssn)references employee(ssn),
foreign key(dno)references department(Dnumber)
)
When I do insertion into table, with the code I get foreign key constraint: 当我插入表时,通过代码我得到了外键约束:
insert into sample.employee(
Fname, Minit, Lname, ssn, Bdate,
Address, sex, salary, Dno
)
values(
'John', 'B', 'Smith', '123456789', 01/09/1965,
'731 fondren,housten', 'M', 30000, '333445555', 5
)
You cannot enter a value to a foreign key if the primary key value doesn't exist. 如果主键值不存在,则不能为外键输入值。 So, Enter the primary key values then try updating the foreign key value accordingly. 因此,输入主键值,然后尝试相应地更新外键值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.