/*==============================================================*/
/* Table: NTB_EMPLOYEEPLAN                                      */
/*==============================================================*//* tablename:要员计划表主表 */create table ntb_employeeplan (
   pk_employeeplan         CHAR(20)                        not null
         /*要员计划表主键*/,
   pk_budget_year          CHAR(4)                         not null
         /*预算年度*/,
   pk_deptdoc              VARCHAR2(40)                    not null
         /*部门编码*/,
   pk_cost_center          VARCHAR2(20)                       not null
         /*成本中心编码*/,
   pk_position             VARCHAR2(48)                    not null       
         /*职位编码*/,
   pk_level                CHAR(20)                        not null  
         /*级别编码*/,   
   pk_staff_type                VARCHAR2(20)                 not null  
         /*人员类别*/,         
   person_count            DECIMAL(8)                        
         /*人数*/,
   headhunter            CHAR(2)         DEFAULT  '2'               
         /*是否需要猎头*/,
   headhunting_fees                    DECIMAL(8)                          
         /*猎头费*/,
   gard                     CHAR(2)         DEFAULT  '2'                               
         /*是否为应届毕业生*/,
   plan_checkin_time       CHAR(6)                           
         /*计划到职时间*/,
   plan_pay                DECIMAL(8)                       
         /*预计合同工资*/,
   add_reason              VARCHAR2(500)
         /*增员理由*/,
   delete_flag             CHAR(2)         DEFAULT  '2'                        
         /*删除标志*/,
   constraint PK_NTB_EMPLOYEEPLAN primary key (pk_employeeplan),
   foreign key (pk_cost_center) references ntb_costcenter(pk_costcenter_id), 
   ts                   char(19)                       default to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),
   dr                   number(10)                     default 0
)/*==============================================================*/
/* Table: NTB_COSTCENTER                                    */
/*==============================================================*//* tablename:NTB_成本中心表 */create table ntb_costcenter (
   pk_costcenter         CHAR(20)                        not null
         /*成本中心表主键*/,
   pk_costcenter_id         VARCHAR2(20)                          not null
         /*成本中心编号*/,
   pk_costcenter_name              VARCHAR2(40)                    not null
         /*成本中心名称*/,
   pk_deptdoc              VARCHAR2(40)                    not null
         /*所属部门*/,
   starttime              CHAR(6)                    not null
         /*开始时间*/,
   endtime              CHAR(6)                    
         /*结束时间*/,      
   delete_flag          CHAR(2)         DEFAULT  '2'                        
         /*删除标志 */,
   constraint PK_NTB_COSTCENTER primary key (pk_costcenter,pk_costcenter_id),
   ts                   char(19)                       default to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),
   dr                   number(10)                     default 0
)

解决方案 »

  1.   

    报错是什么,两个一起执行的话记得末尾加;
    这是两条DML语句该两个;号或者/符号
      

  2.   

    第二个表还没建,怎么能在第一个表里建第二个表的外键?
    应该是第一个表报错吧
    要么就是名为ntb_costcenter 的表已存在?
      

  3.   

    我是一个一个执行的 ,
    上面的写反了.我是先建NTB_COSTCENTER ,再建   NTB_EMPLOYEEPLAN表时就报错了,
    NTB_COSTCENTER 表的PK_NTB_COSTCENTER  对应NTB_EMPLOYEEPLAN  表的pk_cost_center  
    下面这句报的错     
    foreign key (pk_cost_center) references ntb_costcenter(pk_costcenter_id), 
      

  4.   

    constraint FK_NTB_EMPLOYEEPLAN foreign key (pk_cost_center) references ntb_costcenter(pk_costcenter_id), 外键那行改下
      

  5.   

    建表的时候,最好先只建表和主键,外键等表都建好一个用alter table xxx add constraint这样的方法来创建就不会有问题了。或者你见有外键的表时,先建好主表再建从表,这样constraint的references就可以知道主表了。
      

  6.   

    是不是少了constraint 报的错
      

  7.   


    /*==============================================================*/ 
    /* Table: NTB_COSTCENTER                                    */ 
    /*==============================================================*/ /* tablename:NTB_成本中心表 */ create table ntb_costcenter ( 
      pk_costcenter        CHAR(20)                        not null 
            /*成本中心表主键*/, 
      pk_costcenter_id        VARCHAR2(20)                          not null 
            /*成本中心编号*/, 
      pk_costcenter_name              VARCHAR2(40)                    not null 
            /*成本中心名称*/, 
      pk_deptdoc              VARCHAR2(40)                    not null 
            /*所属部门*/, 
      starttime              CHAR(6)                    not null 
            /*开始时间*/, 
      endtime              CHAR(6)                    
            /*结束时间*/,      
      delete_flag          CHAR(2)        DEFAULT  '2'                        
            /*删除标志 */, 
      constraint PK_NTB_COSTCENTER primary key (pk_costcenter_id), --去掉字段pk_costcenter
      ts                  char(19)                      default to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'), 
      dr                  number(10)                    default 0 
    );/*==============================================================*/ 
    /* Table: NTB_EMPLOYEEPLAN                                      */ 
    /*==============================================================*/ /* tablename:要员计划表主表 */ create table ntb_employeeplan ( 
      pk_employeeplan        CHAR(20)                        not null 
            /*要员计划表主键*/, 
      pk_budget_year          CHAR(4)                        not null 
            /*预算年度*/, 
      pk_deptdoc              VARCHAR2(40)                    not null 
            /*部门编码*/, 
      pk_cost_center          VARCHAR2(20)                      not null 
            /*成本中心编码*/, 
      pk_position            VARCHAR2(48)                    not null      
            /*职位编码*/, 
      pk_level                CHAR(20)                        not null  
            /*级别编码*/,  
      pk_staff_type                VARCHAR2(20)                not null  
            /*人员类别*/,        
      person_count            DECIMAL(8)                        
            /*人数*/, 
      headhunter            CHAR(2)        DEFAULT  '2'              
            /*是否需要猎头*/, 
      headhunting_fees                    DECIMAL(8)                          
            /*猎头费*/, 
      gard                    CHAR(2)        DEFAULT  '2'                              
            /*是否为应届毕业生*/, 
      plan_checkin_time      CHAR(6)                          
            /*计划到职时间*/, 
      plan_pay                DECIMAL(8)                      
            /*预计合同工资*/, 
      add_reason              VARCHAR2(500) 
            /*增员理由*/, 
      delete_flag            CHAR(2)        DEFAULT  '2'                        
            /*删除标志*/, 
      constraint PK_NTB_EMPLOYEEPLAN primary key (pk_employeeplan), 
      foreign key (pk_cost_center) references ntb_costcenter(pk_costcenter_id), 
      ts                  char(19)                      default to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'), 
      dr                  number(10)                    default 0 
    ); 
      

  8.   


    /*==============================================================*/ 
    /* Table: NTB_COSTCENTER                                    */ 
    /*==============================================================*/ /* tablename:NTB_成本中心表 */ create table ntb_costcenter ( 
      pk_costcenter        CHAR(20)                        not null 
            /*成本中心表主键*/, 
      pk_costcenter_id        VARCHAR2(20)                          not null 
            /*成本中心编号*/, 
      pk_costcenter_name              VARCHAR2(40)                    not null 
            /*成本中心名称*/, 
      pk_deptdoc              VARCHAR2(40)                    not null 
            /*所属部门*/, 
      starttime              CHAR(6)                    not null 
            /*开始时间*/, 
      endtime              CHAR(6)                    
            /*结束时间*/,      
      delete_flag          CHAR(2)        DEFAULT  '2'                        
            /*删除标志 */, 
      constraint PK_NTB_COSTCENTER primary key (pk_costcenter,pk_costcenter_id), 
      constraint UK_NTB_COSTCENTER unique (pk_costcenter_id),  --或者增加一个唯一性约束
      ts                  char(19)                      default to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'), 
      dr                  number(10)                    default 0 
    );/*==============================================================*/ 
    /* Table: NTB_EMPLOYEEPLAN                                      */ 
    /*==============================================================*/ /* tablename:要员计划表主表 */ create table ntb_employeeplan ( 
      pk_employeeplan        CHAR(20)                        not null 
            /*要员计划表主键*/, 
      pk_budget_year          CHAR(4)                        not null 
            /*预算年度*/, 
      pk_deptdoc              VARCHAR2(40)                    not null 
            /*部门编码*/, 
      pk_cost_center          VARCHAR2(20)                      not null 
            /*成本中心编码*/, 
      pk_position            VARCHAR2(48)                    not null      
            /*职位编码*/, 
      pk_level                CHAR(20)                        not null  
            /*级别编码*/,  
      pk_staff_type                VARCHAR2(20)                not null  
            /*人员类别*/,        
      person_count            DECIMAL(8)                        
            /*人数*/, 
      headhunter            CHAR(2)        DEFAULT  '2'              
            /*是否需要猎头*/, 
      headhunting_fees                    DECIMAL(8)                          
            /*猎头费*/, 
      gard                    CHAR(2)        DEFAULT  '2'                              
            /*是否为应届毕业生*/, 
      plan_checkin_time      CHAR(6)                          
            /*计划到职时间*/, 
      plan_pay                DECIMAL(8)                      
            /*预计合同工资*/, 
      add_reason              VARCHAR2(500) 
            /*增员理由*/, 
      delete_flag            CHAR(2)        DEFAULT  '2'                        
            /*删除标志*/, 
      constraint PK_NTB_EMPLOYEEPLAN primary key (pk_employeeplan), 
      foreign key (pk_cost_center) references ntb_costcenter(pk_costcenter_id), 
      ts                  char(19)                      default to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'), 
      dr                  number(10)                    default 0 
    );