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

Code Example 1

ALTER TABLE ordenes ADD ticket VARCHAR(50) NOT NULL;
ALTER TABLE ordenes ADD CONSTRAINT fk_ticket FOREIGN KEY (ticket) REFERENCES tickets(ticket);
// I'm Horrible Hyena

Code Example 2

ALTER TABLE tryholpz_demo07.core_modules 
ADD COLUMN belongs_to_role INT, 
ADD FOREIGN KEY core_modules(belongs_to_role) REFERENCES role_specific_modules_info(id) ON DELETE CASCADE

Code Example 3

ALTER TABLE ordenes ADD ticket VARCHAR(50) NOT NULL;
ALTER TABLE ordenes ADD CONSTRAINT fk_ticket FOREIGN KEY (ticket) REFERENCES tickets(ticket);

Code Example 4

CREATE TABLE Orders
(

   
OrderID int NOT NULL,

   
OrderNumber int NOT NULL,

   
PersonID int,

   
PRIMARY KEY (OrderID),

   
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)

);

Code Example 5

CREATE TABLE products(
    productId INT AUTO_INCREMENT PRIMARY KEY,
    productName varchar(100) not null,
    categoryId INT NOT NULL,
    CONSTRAINT fk_category
    FOREIGN KEY (categoryId) 
    REFERENCES categories(categoryId)
        ON UPDATE CASCADE
        ON DELETE CASCADE
) ENGINE=INNODB;

Learn ReactJs, React Native from akashmittal.com