1CREATE TABLE product (category INT NOT NULL, id INT NOT NULL,
2price DECIMAL, PRIMARY KEY(category, id)) ENGINE=INNODB;
3CREATE TABLE customer (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
4CREATE TABLE product_order (no INT NOT NULL AUTO_INCREMENT,
5product_category INT NOT NULL,
6product_id INT NOT NULL,
7customer_id INT NOT NULL,
8PRIMARY KEY(no),
9INDEX (product_category, product_id),
10FOREIGN KEY (product_category, product_id)
11REFERENCES product(category, id) ON UPDATE CASCADE ON DELETE RESTRICT,
12INDEX (customer_id),
13FOREIGN KEY (customer_id)
14REFERENCES customer(id)
15) ENGINE=INNODB;
16SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
17WHERE table_name = 'product_order';
18CONSTRAINT_CATALOG	def
19CONSTRAINT_SCHEMA	test
20CONSTRAINT_NAME	product_order_ibfk_1
21UNIQUE_CONSTRAINT_CATALOG	def
22UNIQUE_CONSTRAINT_SCHEMA	test
23UNIQUE_CONSTRAINT_NAME	PRIMARY
24MATCH_OPTION	NONE
25UPDATE_RULE	CASCADE
26DELETE_RULE	RESTRICT
27TABLE_NAME	product_order
28REFERENCED_TABLE_NAME	product
29CONSTRAINT_CATALOG	def
30CONSTRAINT_SCHEMA	test
31CONSTRAINT_NAME	product_order_ibfk_2
32UNIQUE_CONSTRAINT_CATALOG	def
33UNIQUE_CONSTRAINT_SCHEMA	test
34UNIQUE_CONSTRAINT_NAME	PRIMARY
35MATCH_OPTION	NONE
36UPDATE_RULE	RESTRICT
37DELETE_RULE	RESTRICT
38TABLE_NAME	product_order
39REFERENCED_TABLE_NAME	customer
40DROP TABLE product_order;
41DROP TABLE product;
42DROP TABLE customer;
43