如何添加第二个与两个表交互的外键? 例如:
CREATE TABLE Transactions(
TsID INT NOT NULL,
BookingDate TIMESTAMP NOT NULL,
DepartureDate TIMESTAMP NOT NULL,
Passenger INT NOT NULL,
Flight INT NOT NULL,
TYPE BLOB NOT NULL,
Employee INT NOT NULL,
Charges INT NOT NULL,
Discount INT NOT NULL,
fk_ChargesChID INT NOT NULL,
fk_DiscountsDsID INT NOT NULL,
CONSTRAINT pks PRIMARY KEY(TsID),
CONSTRAINT FOREIGN KEY(fk_ChargesChID) REFERENCES Charges(ChID)
CONSTRAINT FOREIGN KEY(fk_EmployeeEmpID) REFERENCES Employee(EmpID)
);
如何让第二个外键工作而不是给我这个错误?:
1064 - 您的SQL语法出错;查看与MariaDB服务器版本对应的手册,以获取正确的语法 附近' CONSTRAINT FOREIGN KEY(fk_EmployeeEmpID)参考 雇员(的EmpID
收费:
CREATE TABLE Charges(
ChID INT NOT NULL,
Title VARCHAR(50) NOT NULL,
Amount INT(255) NOT NULL,
Description VARCHAR(255) NOT NULL,
CONSTRAINT pks PRIMARY KEY(ChID)
);
员工:
CREATE TABLE Employee(
EmpID INT NOT NULL,
NAME VARCHAR(100) NOT NULL,
Adress VARCHAR(100) NOT NULL,
Branch INT(100) NOT NULL,
Designation VARCHAR(100) NOT NULL,
Email VARCHAR(50) NOT NULL,
Tel VARCHAR(25) NOT NULL,
fk_BranchesBrID INT NOT NULL,
PRIMARY KEY(EmpID),
CONSTRAINT FOREIGN KEY(fk_BranchesBrID) REFERENCES Branches(BrID)
);
答案 0 :(得分:1)
你只会忘记,在
CONSTRAINT FOREIGN KEY(fk_ChargesChID) REFERENCES Charges(ChID)
如果它没有解决你的问题,我需要看到其他表
答案 1 :(得分:0)
你没有在transacctions表创建fk_EmployeeEmpID。
CONSTRAINT FOREIGN KEY(Employee) REFERENCES Employee(EmpID)
我想你想这样做:
version: '3.5'
services:
nginx:
ports:
- 8080:8080