I am having a problem creating this table. I am using oracle to create a sql and I have already created the table ITEM but i cannot find the error in this one. Can someone explain where the issue is? This is my code:
CREATE TABLE STOCK(
STOCKID VARCHAR (4) NOT NULL,
MANUFACTUREDATE DATE NOT NULL,
EXPIRYDATE DATE NOT NULL,
QUANTITYONHAND number (4) NOT NULL,
SELLINGPRICE number (4) NOT NULL,
SIZE varchar (10) NOT NULL,
ITEMID varchar(4) NOT NULL,
CONSTRAINT STOCKID PRIMARY KEY(STOCKID),
CONSTRAINT ITEMID_FK FOREIGN KEY
(ITEMID) REFERENCES ITEM(ITEMID)
);
CodePudding user response:
Two and a half issues:
- one is typo (foreign
key
, notket
), - another is invalid column name -
size
is a reserved word, so - rename it to e.g.c_size
) - "half" of the issue is datatype - Oracle recommends us to use
varchar2
, notvarchar
.
After that:
SQL> CREATE TABLE stock
2 (
3 stockid VARCHAR2 (4) NOT NULL,
4 manufacturedate DATE NOT NULL,
5 expirydate DATE NOT NULL,
6 quantityonhand NUMBER (4) NOT NULL,
7 sellingprice NUMBER (4) NOT NULL,
8 c_size VARCHAR2 (10) NOT NULL,
9 itemid VARCHAR2 (4) NOT NULL,
10 CONSTRAINT stockid PRIMARY KEY (stockid),
11 CONSTRAINT itemid_fk FOREIGN KEY (itemid) REFERENCES item (itemid)
12 );
Table created.
SQL>
CodePudding user response:
size
is a reserved keyword in oracle: .
Please rename the column.