Check out example codes for "alter table add foreign key mysql". It will help you in understanding the concepts better.

Code Example 1

ALTER TABLE Orders
ADD 
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID) ON DELETE CASCADE;

Code Example 2

-- On Create
CREATE TABLE tableName (
    ID INT,
    SomeEntityID INT,
    PRIMARY KEY (ID),
    FOREIGN KEY (SomeEntityID)
        REFERENCES SomeEntityTable(ID)
        ON DELETE CASCADE
);

-- On Alter, if the column already exists but has no FK
ALTER TABLE
  tableName
ADD
  FOREIGN KEY (SomeEntityID) REFERENCES SomeEntityTable(ID) ON DELETE CASCADE;

Code Example 3

ALTER TABLE table_name
DROP CONSTRAINT fk_name;

Code Example 4

ALTER TABLE Orders
ADD FOREIGN KEY (PersonID) REFERENCES Persons(PersonID);

Code Example 5

CREATE TABLE Sales.TempSalesReason 
   (
      TempID int NOT NULL, Name nvarchar(50)
      , CONSTRAINT PK_TempSales PRIMARY KEY NONCLUSTERED (TempID)
      , CONSTRAINT FK_TempSales_SalesReason FOREIGN KEY (TempID)
        REFERENCES Sales.SalesReason (SalesReasonID)
        ON DELETE CASCADE
        ON UPDATE CASCADE
   )
;

Code Example 6

ALTER TABLE Orders

ADD FOREIGN KEY (PersonID)
REFERENCES Persons(PersonID);

Learn ReactJs, React Native from akashmittal.com