oracle - SQL error code table doesn't exist...? -
i'm frusterated...i spent 3 hours on , still can't fix these errors...
here's sql tables , values.
create table order_mys ( orderid number(3) not null, orderdate date not null, custid char(5) not null, primary key (orderid), foreign key (custid) references customer_mys ) ;
create table orderdetail_mys ( orderid number(3) not null, productid number(3) not null, productqty number(4) not null, prodcutprice number(6,2) not null, primary key (orderid, productid), foreign key (orderid) references order_mys, foreign key (productid) references product_mys ) ;
error code order table
sql> sql> create table order_mys ( 2 orderid number(3) not null, 3 orderdate date not null, 4 custid char(5) not null, 5 primary key (orderid), 6 foreign key (custid) references customer_mys 7 ) ; foreign key (custid) references customer_mys * error @ line 6: ora-02267: column type incompatible referenced column type
error code orderdetail
sql> create table orderdetail_mys ( 2 orderid number(3) not null, 3 productid number(3) not null, 4 productqty number(4) not null, 5 prodcutprice number(6,2) not null, 6 primary key (orderid, productid), 7 foreign key (orderid) references order_mys, 8 foreign key (productid) references product_mys 9 ) ; foreign key (orderid) references order_mys, * error @ line 7: ora-00942: table or view not exist
table customer_mys
create table customer_mys (
create table customer_mys ( custid varchar(5) not null, custfname varchar(20) not null, custlname varchar(20) not null, custphone char(10), salesrepid number(4) not null, primary key (custid), foreign key (salesrepid) references salesrep_mys ) ;
salesrep_mys table
create table salesrep_mys ( salesrepid number(4) not null, salesrepfname varchar(20) not null, salesreplname varchar(20) not null, deptid number(3) not null, commclass char(1) not null, primary key (salesrepid), foreign key (deptid) references dept_mys, foreign key (commclass) references commission_mys ) ;
salesrep entries
insert salesrep_mys values (10, 'alice', 'jones', 10, 'a') ;
replace order_mys
, try
create table order_mys ( orderid number(3) not null, orderdate date not null, custid varchar(5) not null, primary key (orderid), foreign key (custid) references customer_mys ) ;
while custid
declared type of varchar
in customer_mys
table, trying declare same of type char
in order_mys
table , make foreign key
, cannot referencing columns should of same data type.
if not trying make foreign key, there shouldn't have been issues.