我想创建表并建立它们之间的关系,所以我做了一些工作。虽然我没有发现我编写的代码有任何错误,但我仍然无法解决这个问题。我陷入了这个错误,无法以任何方式修复它。请帮忙。
CREATE TABLE Suppliers (
SupplierID NUMBER PRIMARY KEY NOT NULL,
CompanyName VARCHAR2(255) NOT NULL,
ContactFName VARCHAR2(255) NOT NULL,
ContactLName VARCHAR2(255) NOT NULL,
ContactTitle VARCHAR2(255) NOT NULL,
Address1 VARCHAR2(255) NOT NULL,
Address2 VARCHAR2(255),
City VARCHAR2(255) NOT NULL,
State VARCHAR2(255) NOT NULL,
PostalCode VARCHAR2(255) NOT NULL,
Country VARCHAR2(255) NOT NULL,
Phone VARCHAR2(11) NOT NULL,
Fax VARCHAR2(255) NOT NULL,
Email VARCHAR2(255) NOT NULL,
URL VARCHAR2(255) NOT NULL,
PaymentMethds VARCHAR2(255) NOT NULL,
DiscountType VARCHAR2(255) NOT NULL,
TypeGoods VARCHAR2(255) NOT NULL,
Notes VARCHAR2(255) NOT NULL,
DiscountAvailable VARCHAR2(255) NOT NULL,
CurrentOrder VARCHAR2(255) NOT NULL,
Logo VARCHAR2(255) NOT NULL,
CustomerID NUMBER NOT NULL,
SizeURL VARCHAR2(255)
);
CREATE TABLE Payments (
PaymentID NUMBER NOT NULL PRIMARY KEY,
PaymentType VARCHAR2(255) NOT NULL,
Allowed NUMBER(1,0) NOT NULL
);
CREATE TABLE Shippers (
ShipperID NUMBER NOT NULL PRIMARY KEY,
CompanyName VARCHAR2(255) NOT NULL,
Phone VARCHAR2(11) NOT NULL
);
CREATE TABLE Customers (
CustomerID NUMBER NOT NULL PRIMARY KEY,
FirstName VARCHAR2(255) NOT NULL,
LastName VARCHAR2(255) NOT NULL,
Class VARCHAR2(255) NOT NULL,
Room VARCHAR2(255) NOT NULL,
Building VARCHAR2(255) NOT NULL,
AddressOne VARCHAR2(255) NOT NULL,
AddressTwo VARCHAR2(255) NOT NULL,
City VARCHAR2(255) NOT NULL,
State VARCHAR2(255) NOT NULL,
PostalCode VARCHAR2(255) NOT NULL,
Country VARCHAR2(255) NOT NULL,
Phone VARCHAR2(11) NOT NULL,
Email VARCHAR2(255) NOT NULL,
VoiceMail VARCHAR2(255) NOT NULL,
Password VARCHAR2(255) NOT NULL,
CreditCard VARCHAR2(255) NOT NULL,
CreditCardTypeId VARCHAR2(255) NOT NULL,
CardExpMo VARCHAR2(255) NOT NULL,
BillingAddress VARCHAR2(255) NOT NULL,
BillingCity VARCHAR2(255) NOT NULL,
BillingRegion VARCHAR2(255) NOT NULL,
BillingPostalCode NUMBER NOT NULL,
BillingCountry VARCHAR2(255) NOT NULL,
ShipAddress VARCHAR2(255) NOT NULL,
ShipCity VARCHAR2(255) NOT NULL,
ShipRegion VARCHAR2(255) NOT NULL,
ShipPostalCode NUMBER NOT NULL,
ShipCountry VARCHAR2(255) NOT NULL,
DateEntered VARCHAR2(255) NOT NULL
);
CREATE TABLE Category (
CategoryID NUMBER PRIMARY KEY NOT NULL,
CategoryName VARCHAR2(255) NOT NULL,
Description VARCHAR2(255) NOT NULL,
Picture VARCHAR2(255) NOT NULL,
Active NUMBER(1,0)
);
CREATE TABLE Products (
ProductID NUMBER NOT NULL PRIMARY KEY,
SKU VARCHAR2(255) NOT NULL,
IDSKU VARCHAR2(255) NOT NULL,
VendorProductID NUMBER NOT NULL,
ProductName VARCHAR2(255) NOT NULL,
ProductDescription VARCHAR2(255) NOT NULL,
SupplierID NUMBER NOT NULL,
CategoryID NUMBER NOT NULL,
QuantityPerUnit VARCHAR2(255) NOT NULL,
UnitPrice NUMBER NOT NULL,
MSRP NUMBER NOT NULL,
AvailableSize VARCHAR2(255),
AvailableColors VARCHAR2(255) NOT NULL,
Size NUMBER NOT NULL,
Color VARCHAR2(255) NOT NULL,
Discount VARCHAR2(255) NOT NULL,
UnitWeight VARCHAR2(255) NOT NULL,
UnitsInStock VARCHAR2(255) NOT NULL,
UnitsInOrder VARCHAR2(255) NOT NULL,
ReorderLevel VARCHAR2(255) NOT NULL,
ProductAvailable NUMBER NOT NULL,
DiscountAvailable NUMBER NOT NULL,
CurrentOrder VARCHAR2(255) NOT NULL,
Picture VARCHAR2(255) NOT NULL,
Ranking NUMBER NOT NULL,
Note VARCHAR2(255),
CONSTRAINT fksup FOREIGN KEY (SupplierID) REFERENCES Suppliers(SupplierID),
CONSTRAINT catsup FOREIGN KEY (CategoryID) REFERENCES Category(CategoryID)
);
CREATE TABLE OrderDetails(
OrderID NUMBER NOT NULL,
ProductID NUMBER NOT NULL,
OrderNumber NUMBER NOT NULL,
Price NUMBER NOT NULL,
Quantity NUMBER NOT NULL,
Discount NUMBER NOT NULL,
Total NUMBER NOT NULL,
IDSKU NUMBER NOT NULL,
Size NUMBER NOT NULL,
Color VARCHAR2(255) NOT NULL,
FullFilled VARCHAR2(255),
ShipDate DATE NOT NULL,
OrderDetailID NUMBER NOT NULL PRIMARY KEY,
BillDate DATE NOT NULL,
CONSTRAINT uruncekme FOREIGN KEY (ProductID) REFERENCES Products(ProductID)
);
CREATE TABLE Orders ( OrderID NUMBER NOT NULL PRIMARY KEY,
CustomerID NUMBER NOT NULL,
OrderNumber NUMBER NOT NULL,
PaymentID NUMBER NOT NULL,
OrderDate NUMBER NOT NULL,
ShipDate DATE NOT NULL,
RequiredDate DATE NOT NULL,
ShipperID NUMBER NOT NULL,
Freight VARCHAR2(255) NOT NULL,
SalesTax VARCHAR2(255) ,
TimeStamp VARCHAR2(255) ,
TransactStatus NUMBER(1,0) NOT NULL,
ErrLoc VARCHAR2(255),
ErrMsg VARCHAR2(255),
Fulfilled VARCHAR2(255),
Deleted NUMBER(1,0) NOT NULL,
Paid VARCHAR2(255) NOT NULL,
PaymentDate DATE NOT NULL,
CONSTRAINT siparisdetay FOREIGN KEY (OrderID) REFERENCES OrderDetails(OrderID),
CONSTRAINT odemedetay FOREIGN KEY (PaymentID) REFERENCES Payments(PaymentID),
CONSTRAINT shipperdetay FOREIGN KEY (ShipperID) REFERENCES Shippers(ShipperID),
CONSTRAINT musteridetay FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
);
Table SUPPLIERS created.
Table PAYMENTS created.
Table SHIPPERS created.
Table CUSTOMERS created.
Table CATEGORY created.
Error starting at line : 89 in command -
CREATE TABLE Products (
ProductID NUMBER NOT NULL PRIMARY KEY,
SKU VARCHAR2(255) NOT NULL,
IDSKU VARCHAR2(255) NOT NULL,
VendorProductID NUMBER NOT NULL,
ProductName VARCHAR2(255) NOT NULL,
ProductDescription VARCHAR2(255) NOT NULL,
SupplierID NUMBER NOT NULL,
CategoryID NUMBER NOT NULL,
QuantityPerUnit VARCHAR2(255) NOT NULL,
UnitPrice NUMBER NOT NULL,
MSRP NUMBER NOT NULL,
AvailableSize VARCHAR2(255),
AvailableColors VARCHAR2(255) NOT NULL,
Size NUMBER NOT NULL,
Color VARCHAR2(255) NOT NULL,
Discount VARCHAR2(255) NOT NULL,
UnitWeight VARCHAR2(255) NOT NULL,
UnitsInStock VARCHAR2(255) NOT NULL,
UnitsInOrder VARCHAR2(255) NOT NULL,
ReorderLevel VARCHAR2(255) NOT NULL,
ProductAvailable NUMBER NOT NULL,
DiscountAvailable NUMBER NOT NULL,
CurrentOrder VARCHAR2(255) NOT NULL,
Picture VARCHAR2(255) NOT NULL,
Ranking NUMBER NOT NULL,
Note VARCHAR2(255),
CONSTRAINT fksup FOREIGN KEY (SupplierID) REFERENCES Suppliers(SupplierID),
CONSTRAINT catsup FOREIGN KEY (CategoryID) REFERENCES Category(CategoryID)
)
Error report -
ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error starting at line : 121 in command -
CREATE TABLE OrderDetails(
OrderID NUMBER NOT NULL,
ProductID NUMBER NOT NULL,
OrderNumber NUMBER NOT NULL,
Price NUMBER NOT NULL,
Quantity NUMBER NOT NULL,
Discount NUMBER NOT NULL,
Total NUMBER NOT NULL,
IDSKU NUMBER NOT NULL,
Size NUMBER NOT NULL,
Color VARCHAR2(255) NOT NULL,
FullFilled VARCHAR2(255),
ShipDate DATE NOT NULL,
OrderDetailID NUMBER NOT NULL PRIMARY KEY,
BillDate DATE NOT NULL,
CONSTRAINT uruncekme FOREIGN KEY (ProductID) REFERENCES Products(ProductID)
)
Error report -
ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error starting at line : 140 in command -
CREATE TABLE Orders ( OrderID NUMBER NOT NULL PRIMARY KEY,
CustomerID NUMBER NOT NULL,
OrderNumber NUMBER NOT NULL,
PaymentID NUMBER NOT NULL,
OrderDate NUMBER NOT NULL,
ShipDate DATE NOT NULL,
RequiredDate DATE NOT NULL,
ShipperID NUMBER NOT NULL,
Freight VARCHAR2(255) NOT NULL,
SalesTax VARCHAR2(255) ,
TimeStamp VARCHAR2(255) ,
TransactStatus NUMBER(1,0) NOT NULL,
ErrLoc VARCHAR2(255),
ErrMsg VARCHAR2(255),
Fulfilled VARCHAR2(255),
Deleted NUMBER(1,0) NOT NULL,
Paid VARCHAR2(255) NOT NULL,
PaymentDate DATE NOT NULL,
CONSTRAINT siparisdetay FOREIGN KEY (OrderID) REFERENCES OrderDetails(OrderID),
CONSTRAINT odemedetay FOREIGN KEY (PaymentID) REFERENCES Payments(PaymentID),
CONSTRAINT shipperdetay FOREIGN KEY (ShipperID) REFERENCES Shippers(ShipperID),
CONSTRAINT musteridetay FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
)
Error report -
ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
我从头开始审查了代码并做了一些研究,但我找不到解决方案。
您遇到的错误是由于未创建previous表,因此外键约束失败。未创建的表也会犯同样的错误:您无法命名列
size
,而是将其重命名为其他名称(例如 c_size
)。
此外,您无法在
orderid
表中引用 orderdetails
,因为它不是其主键列(orderdetailid
是)。
修复后,一切正常:
SQL> CREATE TABLE Suppliers (
2 SupplierID NUMBER PRIMARY KEY NOT NULL,
3 CompanyName VARCHAR2(255) NOT NULL,
4 ContactFName VARCHAR2(255) NOT NULL,
5 ContactLName VARCHAR2(255) NOT NULL,
6 ContactTitle VARCHAR2(255) NOT NULL,
7 Address1 VARCHAR2(255) NOT NULL,
8 Address2 VARCHAR2(255),
9 City VARCHAR2(255) NOT NULL,
10 State VARCHAR2(255) NOT NULL,
11 PostalCode VARCHAR2(255) NOT NULL,
12 Country VARCHAR2(255) NOT NULL,
13 Phone VARCHAR2(11) NOT NULL,
14 Fax VARCHAR2(255) NOT NULL,
15 Email VARCHAR2(255) NOT NULL,
16 URL VARCHAR2(255) NOT NULL,
17 PaymentMethds VARCHAR2(255) NOT NULL,
18 DiscountType VARCHAR2(255) NOT NULL,
19 TypeGoods VARCHAR2(255) NOT NULL,
20 Notes VARCHAR2(255) NOT NULL,
21 DiscountAvailable VARCHAR2(255) NOT NULL,
22 CurrentOrder VARCHAR2(255) NOT NULL,
23 Logo VARCHAR2(255) NOT NULL,
24 CustomerID NUMBER NOT NULL,
25 SizeURL VARCHAR2(255)
26 );
Table created.
SQL> CREATE TABLE Payments (
2 PaymentID NUMBER NOT NULL PRIMARY KEY,
3 PaymentType VARCHAR2(255) NOT NULL,
4 Allowed NUMBER(1,0) NOT NULL
5 );
Table created.
SQL> CREATE TABLE Shippers (
2 ShipperID NUMBER NOT NULL PRIMARY KEY,
3 CompanyName VARCHAR2(255) NOT NULL,
4 Phone VARCHAR2(11) NOT NULL
5 );
Table created.
SQL> CREATE TABLE Customers (
2 CustomerID NUMBER NOT NULL PRIMARY KEY,
3 FirstName VARCHAR2(255) NOT NULL,
4 LastName VARCHAR2(255) NOT NULL,
5 Class VARCHAR2(255) NOT NULL,
6 Room VARCHAR2(255) NOT NULL,
7 Building VARCHAR2(255) NOT NULL,
8 AddressOne VARCHAR2(255) NOT NULL,
9 AddressTwo VARCHAR2(255) NOT NULL,
10 City VARCHAR2(255) NOT NULL,
11 State VARCHAR2(255) NOT NULL,
12 PostalCode VARCHAR2(255) NOT NULL,
13 Country VARCHAR2(255) NOT NULL,
14 Phone VARCHAR2(11) NOT NULL,
15 Email VARCHAR2(255) NOT NULL,
16 VoiceMail VARCHAR2(255) NOT NULL,
17 Password VARCHAR2(255) NOT NULL,
18 CreditCard VARCHAR2(255) NOT NULL,
19 CreditCardTypeId VARCHAR2(255) NOT NULL,
20 CardExpMo VARCHAR2(255) NOT NULL,
21 BillingAddress VARCHAR2(255) NOT NULL,
22 BillingCity VARCHAR2(255) NOT NULL,
23 BillingRegion VARCHAR2(255) NOT NULL,
24 BillingPostalCode NUMBER NOT NULL,
25 BillingCountry VARCHAR2(255) NOT NULL,
26 ShipAddress VARCHAR2(255) NOT NULL,
27 ShipCity VARCHAR2(255) NOT NULL,
28 ShipRegion VARCHAR2(255) NOT NULL,
29 ShipPostalCode NUMBER NOT NULL,
30 ShipCountry VARCHAR2(255) NOT NULL,
31 DateEntered VARCHAR2(255) NOT NULL
32 );
Table created.
SQL> CREATE TABLE Category (
2 CategoryID NUMBER PRIMARY KEY NOT NULL,
3 CategoryName VARCHAR2(255) NOT NULL,
4 Description VARCHAR2(255) NOT NULL,
5 Picture VARCHAR2(255) NOT NULL,
6 Active NUMBER(1,0)
7 );
Table created.
SQL> CREATE TABLE Products (
2 ProductID NUMBER NOT NULL PRIMARY KEY,
3 SKU VARCHAR2(255) NOT NULL,
4 IDSKU VARCHAR2(255) NOT NULL,
5 VendorProductID NUMBER NOT NULL,
6 ProductName VARCHAR2(255) NOT NULL,
7 ProductDescription VARCHAR2(255) NOT NULL,
8 SupplierID NUMBER NOT NULL,
9 CategoryID NUMBER NOT NULL,
10 QuantityPerUnit VARCHAR2(255) NOT NULL,
11 UnitPrice NUMBER NOT NULL,
12 MSRP NUMBER NOT NULL,
13 AvailableSize VARCHAR2(255),
14 AvailableColors VARCHAR2(255) NOT NULL,
15 C_Size NUMBER NOT NULL,
16 Color VARCHAR2(255) NOT NULL,
17 Discount VARCHAR2(255) NOT NULL,
18 UnitWeight VARCHAR2(255) NOT NULL,
19 UnitsInStock VARCHAR2(255) NOT NULL,
20 UnitsInOrder VARCHAR2(255) NOT NULL,
21 ReorderLevel VARCHAR2(255) NOT NULL,
22 ProductAvailable NUMBER NOT NULL,
23 DiscountAvailable NUMBER NOT NULL,
24 CurrentOrder VARCHAR2(255) NOT NULL,
25 Picture VARCHAR2(255) NOT NULL,
26 Ranking NUMBER NOT NULL,
27 Note VARCHAR2(255),
28 CONSTRAINT fksup FOREIGN KEY (SupplierID) REFERENCES Suppliers(SupplierID),
29 CONSTRAINT catsup FOREIGN KEY (CategoryID) REFERENCES Category(CategoryID)
30 );
Table created.
SQL> CREATE TABLE OrderDetails(
2 OrderID NUMBER NOT NULL,
3 ProductID NUMBER NOT NULL,
4 OrderNumber NUMBER NOT NULL,
5 Price NUMBER NOT NULL,
6 Quantity NUMBER NOT NULL,
7 Discount NUMBER NOT NULL,
8 Total NUMBER NOT NULL,
9 IDSKU NUMBER NOT NULL,
10 C_Size NUMBER NOT NULL,
11 Color VARCHAR2(255) NOT NULL,
12 FullFilled VARCHAR2(255),
13 ShipDate DATE NOT NULL,
14 OrderDetailID NUMBER NOT NULL PRIMARY KEY,
15 BillDate DATE NOT NULL,
16 CONSTRAINT uruncekme FOREIGN KEY (ProductID) REFERENCES Products(ProductID)
17 );
Table created.
SQL> CREATE TABLE Orders ( OrderID NUMBER NOT NULL PRIMARY KEY,
2 CustomerID NUMBER NOT NULL,
3 OrderNumber NUMBER NOT NULL,
4 PaymentID NUMBER NOT NULL,
5 OrderDate NUMBER NOT NULL,
6 ShipDate DATE NOT NULL,
7 RequiredDate DATE NOT NULL,
8 ShipperID NUMBER NOT NULL,
9 Freight VARCHAR2(255) NOT NULL,
10 SalesTax VARCHAR2(255) ,
11 TimeStamp VARCHAR2(255) ,
12 TransactStatus NUMBER(1,0) NOT NULL,
13 ErrLoc VARCHAR2(255),
14 ErrMsg VARCHAR2(255),
15 Fulfilled VARCHAR2(255),
16 Deleted NUMBER(1,0) NOT NULL,
17 Paid VARCHAR2(255) NOT NULL,
18 PaymentDate DATE NOT NULL,
19 CONSTRAINT siparisdetay FOREIGN KEY (OrderID) REFERENCES OrderDetails(OrderDETAILID),
20 CONSTRAINT odemedetay FOREIGN KEY (PaymentID) REFERENCES Payments(PaymentID),
21 CONSTRAINT shipperdetay FOREIGN KEY (ShipperID) REFERENCES Shippers(ShipperID),
22 CONSTRAINT musteridetay FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
23 );
Table created.
SQL>