代码:
CREATE TABLE Inventory (
InventoryNumber INT PRIMARY KEY,
ProductCode VARCHAR(10),
ColorCode VARCHAR(10),
Size VARCHAR(10) NOT NULL,
Price DECIMAL(10,2) NOT NULL,
QuantityOnHand INT NOT NULL,
CONSTRAINT CHK_Inventory_Size CHECK (Size IN ('S', 'M', 'L', 'XL', 'XXL')),
CONSTRAINT CHK_Inventory_Price CHECK (Price <= 9999.99),
CONSTRAINT CHK_Inventory_QuantityOnHand CHECK (QuantityOnHand >= 0),
CONSTRAINT FK_Inventory_Product FOREIGN KEY (ProductCode) REFERENCES Product(ProductCode),
CONSTRAINT FK_Inventory_Color FOREIGN KEY (ColorCode) REFERENCES Color(ColorCode),
UNIQUE (ProductCode, ColorCode, Size)
);
Error report -
ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
SIZE
是保留字,不能用作不带引号的标识符。
使用不同的标识符:
CREATE TABLE Inventory (
InventoryNumber INT PRIMARY KEY,
ProductCode,
ColorCode,
ItemSize VARCHAR(10) NOT NULL,
Price DECIMAL(10,2) NOT NULL,
QuantityOnHand INT NOT NULL,
CONSTRAINT CHK_Inventory_Size CHECK (ItemSize IN ('S', 'M', 'L', 'XL', 'XXL')),
CONSTRAINT CHK_Inventory_Price CHECK (Price <= 9999.99),
CONSTRAINT CHK_Inventory_QuantityOnHand CHECK (QuantityOnHand >= 0),
CONSTRAINT FK_Inventory_Product FOREIGN KEY (ProductCode) REFERENCES Product(ProductCode),
CONSTRAINT FK_Inventory_Color FOREIGN KEY (ColorCode) REFERENCES Color(ColorCode),
UNIQUE (ProductCode, ColorCode, ItemSize)
);
或使用带引号的标识符(尽管这不被认为是好的做法,因为您必须在使用列的所有地方都使用带引号的标识符):
CREATE TABLE Inventory (
InventoryNumber INT PRIMARY KEY,
ProductCode,
ColorCode,
"Size" VARCHAR(10) NOT NULL,
Price DECIMAL(10,2) NOT NULL,
QuantityOnHand INT NOT NULL,
CONSTRAINT CHK_Inventory_Size CHECK ("Size" IN ('S', 'M', 'L', 'XL', 'XXL')),
CONSTRAINT CHK_Inventory_Price CHECK (Price <= 9999.99),
CONSTRAINT CHK_Inventory_QuantityOnHand CHECK (QuantityOnHand >= 0),
CONSTRAINT FK_Inventory_Product FOREIGN KEY (ProductCode) REFERENCES Product(ProductCode),
CONSTRAINT FK_Inventory_Color FOREIGN KEY (ColorCode) REFERENCES Color(ColorCode),
UNIQUE (ProductCode, ColorCode, "Size")
);