简体   繁体   English

PHP数据库外键

[英]PHP database foreign key

I have this piece of code 我有这段代码

CONSTRAINT has FOREIGN KEY(fk_AirFareAfID) REFERENCES AirFare(AfID)

and it's giving me this error: 这给了我这个错误:

#1064 - You have an error in your SQL syntax; check the manual that 
corresponds to your MariaDB server version for the right syntax to use 
near 'have FOREIGN KEY(fk_ChargesChID) REFERENCES Charges(ChID)

What could be the problem? 可能是什么问题呢?

Full code of the part: 该部分的完整代码:

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 can have FOREIGN KEY(fk_ChargesChID) REFERENCES Charges(ChID)
)

Remove "can have"... 删除“可以拥有” ...

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) )

... or replace it with a symbol , which is the name for the constraint. ...或将其替换为symbol ,即约束的名称。 You can't use two words there. 您不能在那里使用两个词。 You've done this in the line above where pks is your symbol . 您已经在pks是您的symbol上方的行中完成了此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM