1
2
3
4
5 CREATE TABLE products(
6 productId INT AUTO_INCREMENT PRIMARY KEY,
7 productName varchar(100) not null,
8 categoryId INT NOT NULL,
9 CONSTRAINT fk_category
10 FOREIGN KEY (categoryId)
11 REFERENCES categories(categoryId)
12 ON UPDATE CASCADE
13 ON DELETE CASCADE
14) ENGINE=INNODB;
1mysql > create unique index index_bar_id on foos(bar_id);
2mysql > alter table foos add constraint index_bar_id foreign key (bar_id) references bars (id);
3