
INSERT 语句与 FOREIGN KEY 约束"FK__person__Deptno__36B12243"冲突。该冲突发生于数据库"Employee"
useEmployeecreatetablesalary(Pnochar(6)notnullprimarykey,basedec(5)nullcheck(base>=30...
use Employee
create table salary
(
Pno char(6) not null primary key,
base dec(5) null check(base>=300),
Bonus dec(5) null check(bonus>=50),
Month int not null,
fact dec(5) null
)
create table department
(
Deptno char(4) not null primary key,
Dname varchar(10) not null
)
create table person
(
Pno char(6) not null primary key,
Pname varchar(10) not null,
Sex char(2) not null,
Birthday Datetime null,
Prof varchar(10) null,
Deptno char(4) not null foreign key (Deptno) references department(Deptno))
insert into person values('000007','张','男','1990-01-01','高级','001');
insert into person values('000008','王','男','1990-01-01','初级','002');
insert into person values('000009','孙','男','1990-01-01','高级','004');
insert into person values('000000','钱','男','1990-01-01','高级','003');
这个外键的冲突怎么解决啊?? 展开
create table salary
(
Pno char(6) not null primary key,
base dec(5) null check(base>=300),
Bonus dec(5) null check(bonus>=50),
Month int not null,
fact dec(5) null
)
create table department
(
Deptno char(4) not null primary key,
Dname varchar(10) not null
)
create table person
(
Pno char(6) not null primary key,
Pname varchar(10) not null,
Sex char(2) not null,
Birthday Datetime null,
Prof varchar(10) null,
Deptno char(4) not null foreign key (Deptno) references department(Deptno))
insert into person values('000007','张','男','1990-01-01','高级','001');
insert into person values('000008','王','男','1990-01-01','初级','002');
insert into person values('000009','孙','男','1990-01-01','高级','004');
insert into person values('000000','钱','男','1990-01-01','高级','003');
这个外键的冲突怎么解决啊?? 展开
展开全部
外键冲突,外键表的值必须是主键表中已存在的
你的数据可能是department表中没有deptno相应的值,要先个这个表添加相应的值才能给person表加
你的数据可能是department表中没有deptno相应的值,要先个这个表添加相应的值才能给person表加
展开全部
如果不能取消该外键约束,请在创建表时将键名更改一下吧。
追问
和键名有关系吗,具体怎么改啊,求教啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
保证插入person的字段Deptno 在department的字段Deptno都有就可以了
追问
可以详细点吗,真的很急着用的
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询