創建表我試圖運行下面的SQL腳本:得到錯誤,而在MySQL
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 fkinvoice FOREIGN KEY (Invno) REFERENCES invoice(Invno), CONSTRAINT fkpart FOREIGN KEY (Partno) REFERENCES part(Partno) ); DROP TABLE invprod; DROP TABLE invoice; DROP TABLE orderprod; DROP TABLE orders; DROP TABLE customer; DROP TABLE salesrep; DROP TABLE part;*
我不能創建表invprod。我收到錯誤:69無法創建表'sh.invprod'(errno:121)。我在這個腳本中犯了什麼錯誤?
如果您執行'show innodb status',則在輸出中間埋入一個更詳細的「最後一個錯誤」部分,該部分應該更好地解釋爲什麼無法創建表。 –
您使用的是哪個版本的MySQL?我剛剛在5.1.57上試過了,它運行良好 – DaveyBoy
你的腳本對我來說工作正常,除了最後刪除'*'。你使用的是什麼版本的SQLite? – Dave