alter table add primary key mysql code example
Example 1: alter table add foreign key mysql
ALTER TABLE orders
ADD
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
Example 2: MySQL Primary Key
Typically, you define the primary key for a table in the CREATE TABLE statement.
If the primary key has one column, you can use the PRIMARY KEY constraint as a column constraint:
CREATE TABLE table_name(
primary_key_column datatype PRIMARY KEY,
...
);