简体   繁体   中英

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. You can't use two words there. You've done this in the line above where pks is your symbol .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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