2
2
# Test syntax of foreign keys
6
drop table if exists t1;
10
a int not null references t2,
11
b int not null references t2 (c),
13
foreign key (a) references t3 match full,
14
foreign key (a) references t3 match partial,
15
foreign key (a,b) references t3 (c,d) on delete no action
17
foreign key (a,b) references t3 (c,d) on update cascade,
18
foreign key (a,b) references t3 (c,d) on delete set default,
19
foreign key (a,b) references t3 (c,d) on update set null);
21
create index a on t1 (a);
22
create unique index b on t1 (a,b);
5
CREATE TABLE product (category INT NOT NULL, id INT NOT NULL,
7
PRIMARY KEY(category, id)) ENGINE=INNODB;
8
CREATE TABLE customer (id INT NOT NULL,
9
PRIMARY KEY (id)) ENGINE=INNODB;
10
CREATE TABLE product_order (no INT NOT NULL AUTO_INCREMENT,
11
product_category INT NOT NULL,
12
product_id INT NOT NULL,
13
customer_id INT NOT NULL,
15
INDEX (product_category, product_id),
16
FOREIGN KEY (product_category, product_id)
17
REFERENCES product(category, id)
18
ON UPDATE CASCADE ON DELETE RESTRICT,
20
FOREIGN KEY (customer_id)
21
REFERENCES customer(id)) ENGINE=INNODB;
23
show create table product_order;
25
drop table product_order, customer, product;