我用以下文字制作这个表格:
CREATE TABLE part
(Partno CHAR(4) PRIMARY KEY,
Partdesc VARCHAR(20),
Onhand INTEGER,
Partclass CHAR(2) check (Partclass IN ( AP , HW , KI , SP )),
Unitprice DECIMAL(6,2)
);
CREATE TABLE salesrep
(Srepno CHAR(3),
Srepname VARCHAR(25),
Srepstreet VARCHAR(30),
Srepcity VARCHAR(15) NOT NULL,
Srepprov VARCHAR(3) NOT NULL,
Sreppcode VARCHAR(6) NOT NULL,
Totcomm DECIMAL(8,2),
Commrate DECIMAL(3,2),
CONSTRAINT pkslsrep PRIMARY KEY (Srepno)
);
CREATE TABLE customer
(Custno CHAR(3),
Custname VARCHAR(25) NOT NULL,
Custstreet VARCHAR(30) NOT NULL,
Custcity VARCHAR(15) NOT NULL,
Custprov VARCHAR(3) NOT NULL,
Custpcode VARCHAR(6) NOT NULL,
Disc DECIMAL(3,1),
Balance DECIMAL(7,2),
Credlimit DECIMAL(5),
Srepno CHAR(3),
CONSTRAINT pkcustno PRIMARY KEY (Custno),
CONSTRAINT fksrepno FOREIGN KEY (Srepno) REFERENCES salesrep(Srepno)
);
CREATE TABLE orders
(Orderno CHAR(5) UNIQUE NOT NULL,
Orderdate DATE,
Custno CHAR(3) NOT NULL,
CONSTRAINT fkordercust FOREIGN KEY (Custno) REFERENCES customer (Custno)
);
CREATE TABLE orderprod
(Orderno CHAR(5),
Partno CHAR(4),
Orderqty INTEGER CHECK (Orderqty>0),
Orderprice DECIMAL(7,2),
CONSTRAINT pkorderprod PRIMARY KEY (Orderno, Partno),
CONSTRAINT fkordprdord FOREIGN KEY (Orderno) REFERENCES orders(Orderno),
CONSTRAINT fkordprdpar FOREIGN KEY (Partno) REFERENCES part(Partno)
);
CREATE TABLE invoice
( Invno CHAR(6),
Invdate DATE,
Orderno CHAR(5),
CONSTRAINT fkinvoice FOREIGN KEY (Orderno) REFERENCES orders(Orderno),
CONSTRAINT pkinvoice PRIMARY KEY (Invno)
);
CREATE TABLE invprod
( Invno CHAR(6),
Partno CHAR(4),
Shipqty INTEGER CHECK (Shipqty>0),
CONSTRAINT fkinvoic FOREIGN KEY (Invno) REFERENCES invoice(Invno),
CONSTRAINT fkpart FOREIGN KEY (Partno) REFERENCES part(Partno)
);
然后,我尝试用以下文字补充一些记录:
INSERT INTO part(Partno, Partdesc, Onhand, Partclass, Unitprice) VALUES( 1542 , Exhaust Fans , 32 , KI , 259.99 );
INSERT INTO part(Partno, Partdesc, Onhand, Partclass, Unitprice) VALUES( 1489 , Washing Machine IFB , 10 , AP , 1499.99 );
INSERT INTO part(Partno, Partdesc, Onhand, Partclass, Unitprice) VALUES( 1378 , Cleaning Kit , 40 , HW , 19.99 );
INSERT INTO part(Partno, Partdesc, Onhand, Partclass, Unitprice) VALUES( 1256 , Soccer Ball , 15 , SP , 20.99 );
INSERT INTO salesrep(Srepno, Srepname, Srepstreet, Srepcity, Srepprov, Sreppcode, Totcomm, Commrate) VALUES( 125 , Dwayne Johnson , Aidelaide Street , Toronto , ON , L6T7U7 , 2566.58 , 12 );
INSERT INTO salesrep(Srepno, Srepname, Srepstreet, Srepcity, Srepprov, Sreppcode, Totcomm, Commrate) VALUES( 147 , Sean Mathews , Hurontario Street , Brampton , ON , L6Y5H7 , 3400.89 , 15 );
INSERT INTO customer(Custno, Custname, Custstreet, Custcity, Custprov, Custpcode, Disc, Balance, Credlimit, Srepno) VALUES( 589 , Ankur Kaushal , Listcreek Road , Brampton , ON , L6P2N7 , 20.0 , 0.00 , 500 , 125 );
INSERT INTO customer(Custno, Custname, Custstreet, Custcity, Custprov, Custpcode, Disc, Balance, Credlimit, Srepno) VALUES( 458 , Iqbal Jassal , Bayridge Dr , Brampton , ON , L7U5D5 , 10.0 , 100.00 , 500 , 147 );
INSERT INTO orders(Orderno, Orderdate, Custno) VALUES( 14587 , 2011-11-09 , 125 );
INSERT INTO orders(Orderno, Orderdate, Custno) VALUES( 11547 , 2011-11-07 , 125 );
INSERT INTO orderprod(Orderno, Partno, Orderqty, Orderprice) VALUES( 14587 , 1256 , 2 , 41.98 );
INSERT INTO orderprod(Orderno, Partno, Orderqty, Orderprice) VALUES( 11547 , 1489 , 1 , 1499.99 );
INSERT INTO invoice(Invno, Invdate, Orderno) VALUES( 578977 , 2011-11-09 , 14587 );
INSERT INTO invprod(Invno, Partno, Shipqty) VALUES( 578977 , 1256 , 2 );
But I am encountering Script line: 12 Out of range value for column Commrate at row 1 Any mistake I am making?