gpt4 book ai didi

mysql - 创建表时出错

转载 作者:行者123 更新时间:2023-11-30 00:23:25 25 4
gpt4 key购买 nike

这是我的声明,我在 Customer_T 上遇到错误。错误指出:

"01:22:05   DROP TABLE customer_t   Error Code: 1051. Unknown table 'energyefficient.customer_t'    0.016 sec"

CREATE TABLE Customer_t
(CustomerID INT NOT NULL,
Name VARCHAR(45) NOT NULL,
Address VARCHAR(256) ,
Email VARCHAR(100) ,
Phone VARCHAR(16) ,
CONSTRAINT PK_CustomerID PRIMARY KEY (CustomerID));


CREATE TABLE Order_t
(OrderID INT NOT NULL,
OrderDate DATE NULL,
CustomerID INT NOT NULL,
CONSTRAINT PK_OrderID PRIMARY KEY (OrderID),
CONSTRAINT FK_CustomerID FOREIGN KEY (CustomerID) REFERENCES customer_t(CustomerID));

CREATE TABLE Equipment
(EquipmentID INT NOT NULL,
EquipmentType VARBINARY(12) ,
YearOfManufacture INT ,
Cost DECIMAL(9,2) ,
Maker VARCHAR(45) ,
Model VARCHAR(45) ,
CustomerID INT ,
CONSTRAINT EquipmentID_PK PRIMARY KEY (EquipmentID),
CONSTRAINT CustomerID_FK FOREIGN KEY (CustomerID) REFERENCES Customer_t(CustomerID));

CREATE TABLE Order_Line_t
(OrderLineID INT NOT NULL,
OrderID INT NOT NULL,
EquipmentID INT NOT NULL,
OrderLineCost DECIMAL(9,2) ,
CONSTRAINT OrderLineID_PK PRIMARY KEY (OrderLineID),
CONSTRAINT OrderID_FK1 FOREIGN KEY (OrderID) REFERENCES Order_t(OrderID),
CONSTRAINT EquipmentID_FK2 FOREIGN KEY (EquipmentID) REFERENCES Equipment_t(EquipmentID));

CREATE TABLE MaintenanceSchedule_t
(MaintenanceID INT NOT NULL,
MaintenanceType VARCHAR(45) NOT NULL,
Schedule_Date DATE NOT NULL,
EquipmentID INT NOT NULL,
ServiceID INT ,
CONSTRAINT MaintenanceID_PK PRIMARY KEY (MaintenanceID),
CONSTRAINT EquipmentID_FK3 FOREIGN KEY (EquipmentID) REFERENCES Equipment(EquipmentID));

CREATE TABLE Service
(ServiceID INT NOT NULL,
EstimatedCost DECIMAL(9,2) NOT NULL,
Status VARCHAR(16) NOT NULL,
ServiceDate DATE ,
EquipmentID INT NOT NULL,
EmployeeID INT NOT NULL,
ActualCost DECIMAL(9,2) ,
ServiceType VARCHAR(45) NOT NULL,
Notes VARCHAR(2000) ,

CONSTRAINT ServiceID_PK PRIMARY KEY (ServiceID),
CONSTRAINT EquipmentID_FK FOREIGN KEY (EquipmentID) REFERENCES Equipment(EquipmentID));

CREATE TABLE Employee_t
(EmployeeID INT NOT NULL,
AnnualSalary DECIMAL(9,2) ,
Name VARCHAR(45) NOT NULL,
DOB DATE ,
POSITION VARCHAR(45) ,
CONSTRAINT EmployeeID_PK PRIMARY KEY (EmployeeID));

最佳答案

尝试使用这个:

设置foreign_key_checks = 0;删除表 energy effective.customer_t;设置foreign_key_checks=1;

有时需要将外键检查设置为0;

谢谢

关于mysql - 创建表时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23055336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com