SQL表创建时出错

时间:2014-02-15 17:46:17

标签: sql oracle

我想创建一个数据库表sales_order。

我的代码如下:

create table sales_order( 
ono varchar2(6) check(ono like 'o%'), 
cno varchar2(6), 
orderdate date not null, 
deladder varchar2(30), 
sno varchar2(6), 
deltype char(1) check (deltype in('P','F')), 
bill char(1), 
delydate date CHECK(delydate>orderdate), 
orderstatus varcahr2(10) set default('inprocess','fullfilled','backorder' 'cancelled'),   constraint p5 primary key(ono), constraint f3 foreign key(sno) references salesman_master(sno)       );

给出以下错误:

 delydate date CHECK(delydate>orderdate),
*
ERROR at line 9:
ORA-02438: Column check constraint cannot reference other columns

1 个答案:

答案 0 :(得分:2)

SQL Fiddle中的错误很明显:

Schema Creation Failed: ORA-02438: Column check constraint cannot reference other columns

然后当您修复其他错误(set defaultvarcahr2?没有关闭))时,它可以正常工作。试试这个:

create table sales_order ( 
    ono varchar2(6) check(ono like 'o%'), 
    cno varchar2(6), 
    orderdate date not null, 
    deladder varchar2(30), 
    sno varchar2(6), 
    deltype char(1) check (deltype in('P','F')), 
    bill char(1), 
    delydate date, 
    orderstatus varchar2(10) check (orderstatus in ('inprocess', 'fullfilled', 'backorder', 'cancelled')),
    constraint p5 primary key(ono),
    constraint f3 foreign key(sno) references salesman_master(sno)
);