超出第1列“通信”的范围值

时间:2011-11-23 23:21:00

标签: mysql sql

我使用以下SQL脚本

创建了此表
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');

但是我遇到'脚本行:12第1行的'Commrate'栏超出范围值 “ 我犯的任何错误?

2 个答案:

答案 0 :(得分:1)

十进制(3,2)表示允许的最大值为9.99

查看官方手册

http://dev.mysql.com/doc/refman/5.0/en/precision-math-decimal-changes.html

答案 1 :(得分:1)

DECIMAL(3,2)有3位数,精度为2位小数。这意味着您只能存储高达9.99

的值

DECIMAL

上的MySQL文档