用java写的sql语句
程序没问题 应该是sql语句出问题了
报错是“违反完整约束条件 (XIAON.FK_DOCTOR_DEPT) - 未找到父项关键字”有两个表 医生表create table T_Doctor
(
  doctor_id         varchar2(32) primary key,
  name               varchar2(30) not null,
  role_id            varchar2(32),
  password           varchar2(16) not null,
  age                number(3) not null,
  sex                char(1) not null,
  dept_id            varchar2(32),
  mobile_phone       varchar2(11) not null,
  office_phone       varchar2(12) not null,
  desc_context       varchar2(500),
  created_date       date default sysdate,
  updated_date       date,
  updated_man        nvarchar2(32)
)
科室表
---科室表
create table T_Department(
dept_id varchar2(32) primary key,
dept_name varchar(20) not null,
created_date date default sysdate,
updated_date date,
updated_man varchar2(32)); ---添加外键约束
alter table T_Doctor add constraint fk_doctor_dept foreign key (dept_id) references T_Department(dept_id)
报错如上
sql:update t_doctor set name='关羽',password='gy',age=60,sex='0',dept_id='1',mobile_phone='5555',
office_phone='5555',desc_context='关羽',updated_date=sysdate,updated_man='admin'
where doctor_id='39';是sql语句写的有问题吗(赋的值都是问号,我直接写出来了)
怎么写sql语句?

解决方案 »

  1.   

    当你update t_doctor的时候,修改了dept_id='1',而这个是引用的t_department,你应该是违反了外键约束
      

  2.   

    当你update t_doctor的时候,修改了dept_id='1',而这个是引用的t_department,你应该是违反了外键约束
      

  3.   

    T_Department表中没有dept_id为1的值,所以就违背了外键约束
      

  4.   

    确保你修改t_doctor的时候,修改的dept_id的值在t_department中有这个值
      

  5.   


    update t_doctor set name='关羽',password='gy',age=60,sex='0',dept_id='1',mobile_phone='5555',
    office_phone='5555',desc_context='关羽',updated_date=sysdate,updated_man='admin'
    where doctor_id='39';
    这句话直接在pl/sql中执行 没有问题