【问题标题】:creating table in in cmd [duplicate]在cmd中创建表[重复]
【发布时间】:2015-07-18 17:04:26
【问题描述】:
create table reservation
(
   reservationid varchar2(6) primary key,
   userid varchar2(6) foreign key references userprofile(userid),
   vehicleid varchar2(6) foreign key references vehicle(vehicleid),
   routeid varchar2(8) foreign key references route(routeid),
   bookingdate date not null,
   journeydate date not null,
   driverid varchar2(6) foreign key references driver(driverid),
   bookingstatus varchar2(20) not null,
   totalfare number(10) not null,
   boardingpoint varchar2(30) not null,
   droppoint varchar2(30) not null,
   vname varchar2(20) not null 
);

我收到一个错误:

第 1 行的错误: ORA-00907: 缺少右括号

【问题讨论】:

    标签: sql oracle


    【解决方案1】:

    内联引用不需要foreign key。此代码适用于SQL Fiddle

    create table vehicle (vehicleid varchar2(6) primary key);
    create table userprofile (userid varchar2(6) primary key);
    create table route (routeid varchar2(8) primary key);
    create table driver (driverid varchar2(6) primary key);
    
    create table reservation
    (
       reservationid varchar2(6) primary key,
       userid varchar2(6) references userprofile(userid) ,
       vehicleid varchar2(6) references vehicle(vehicleid),
       routeid varchar2(8) references route(routeid),
       bookingdate date not null,
       journeydate date not null,
       driverid varchar2(6) references driver(driverid),
       bookingstatus varchar2(20) not null,
       totalfare number(10) not null,
       boardingpoint varchar2(30) not null,
       droppoint varchar2(30) not null,
       vname varchar2(20) not null 
    );
    

    【讨论】:

    • thnx .........但我仍然收到错误
    • SQL> 创建表reservation(reservationid varchar2(6) 主键,userid varch ar2(6) 引用userprofile(userid),vehicleid varchar2(6) 引用vehicle(v ehicleid),routeid varchar2(8 ( 30) 不为空,droppoint varchar2(30) 不为空,vname varchar2(20) 不为空);
    • * 第 1 行出现错误:ORA-02270:此列列表没有匹配的唯一键或主键
    • @faiyazsayeed 。 . .您需要使用正确的主键正确声明引用的表。
    猜你喜欢
    • 2014-06-04
    • 2017-06-08
    • 1970-01-01
    • 2018-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多