我的SQL数据库出错

时间:2017-10-23 07:41:49

标签: mysql sql

我无法让我的SQL表工作。它不断给我一个错误,即由于未经许可或不存在而无法删除表。而且它告诉我那里也有一张无效的表格。

我目前有:

drop table Orders
drop table Item
drop table Supplier
drop table Staff
drop table Customers
drop table Ingredient



CREATE TABLE Supplier(
SupplierNo CHAR(7) PRIMARY KEY,
SupplierName CHAR(25),
SupplierAddress VARCHAR(25),
SupplierPhone CHAR(10),
SupplierContactPerson CHAR (35)
)
go


CREATE TABLE Item (
ItemNo      CHAR(7)     PRIMARY KEY,
ItemName    CHAR(10),
ItemType    CHAR(10),
Price       DEC(3,2),
IngredientCode CHAR (5),

FOREIGN KEY(IngredientCode) REFERENCES Ingredient(IngredientCode)
)
go

CREATE TABLE Staff (
EmployeeID CHAR(3) PRIMARY KEY,
FirstName  CHAR(10),
LastName CHAR(10),
PostalAddress VARCHAR(MAX),
ContactNumber CHAR (10),
RateOfPay     MONEY,
EmployementStatus CHAR(25)
)

CREATE TABLE Customers (
CustomerID CHAR(4) PRIMARY KEY,
CustomerFN CHAR(25),
CustomerLN CHAR(25),
CustomerPhN CHAR(11),
CAddress VARCHAR (25)
)
go

CREATE TABLE Ingredient(
IngredientCode CHAR (5) PRIMARY KEY,
IngredientName CHAR(25),
IngredientDesc VARCHAR(max),
CurrentStockLevel CHAR(3),
PreviousStockLevel CHAR(3),
SuggestedStockLevel CHAR(3),
SupplierNo CHAR(7),
Supplied DATE(),

FOREIGN KEY(SupplierNo) REFERENCES Supplier(SupplierNo)
)

CREATE TABLE Orders(
OrderNo CHAR(7),
OrderDate DATE(),
CustomerNo CHAR(4) FOREIGN KEY,
EmployeeID CHAR(3) FOREIGN KEY,
ItemNo      CHAR(7) FOREIGN KEY,
TypeOfOrder CHAR(10),
TotalAmount MONEY(),
PaymentMethod CHAR(10),
OrderStatus CHAR(10)

FOREIGN KEY CustomerNo, EmployeeID, ItemNo
REFERENCES Customer(CustomerNo), Staff(EmployeeID), Item(ItemNo)
)

这似乎是一个非常简单的问题,但是我甚至不确定这对我没有许可意味着什么或者表格根本不存在...

1 个答案:

答案 0 :(得分:0)

在创建表格成分

之前创建约束

FOREIGN KEY(IngredientCode)参考文献成分(IngredientCode)