2
# Test syntax of foreign keys
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;
30
# Bug#34455 (Ambiguous foreign keys syntax is accepted)
34
drop table if exists t_34455;
37
# 2 match clauses, illegal
38
--error ER_PARSE_ERROR
39
create table t_34455 (
41
foreign key (a) references t3 (a) match full match partial);
43
# match after on delete, illegal
44
--error ER_PARSE_ERROR
45
create table t_34455 (
47
foreign key (a) references t3 (a) on delete set default match full);
49
# match after on update, illegal
50
--error ER_PARSE_ERROR
51
create table t_34455 (
53
foreign key (a) references t3 (a) on update set default match full);
55
# 2 on delete clauses, illegal
56
--error ER_PARSE_ERROR
57
create table t_34455 (
59
foreign key (a) references t3 (a)
60
on delete set default on delete set default);
62
# 2 on update clauses, illegal
63
--error ER_PARSE_ERROR
64
create table t_34455 (
66
foreign key (a) references t3 (a)
67
on update set default on update set default);
69
create table t_34455 (a int not null);
71
# 2 match clauses, illegal
72
--error ER_PARSE_ERROR
74
add foreign key (a) references t3 (a) match full match partial);
76
# match after on delete, illegal
77
--error ER_PARSE_ERROR
79
add foreign key (a) references t3 (a) on delete set default match full);
81
# match after on update, illegal
82
--error ER_PARSE_ERROR
84
add foreign key (a) references t3 (a) on update set default match full);
86
# 2 on delete clauses, illegal
87
--error ER_PARSE_ERROR
89
add foreign key (a) references t3 (a)
90
on delete set default on delete set default);
92
# 2 on update clauses, illegal
93
--error ER_PARSE_ERROR
95
add foreign key (a) references t3 (a)
96
on update set default on update set default);