~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#
2
# Test syntax of foreign keys
3
#
4
722 by Brian Aker
Updated/fix to foreign key test.
5
CREATE TABLE product (category INT NOT NULL, id INT NOT NULL,
6
    price DECIMAL,
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,
14
    PRIMARY KEY(no),
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,
19
    INDEX (customer_id),
20
    FOREIGN KEY (customer_id)
21
    REFERENCES customer(id)) ENGINE=INNODB;
22
23
show create table product_order;
24
25
drop table product_order, customer, product;
1 by brian
clean slate
26
27
# End of 4.1 tests
28
29
#
30
# Bug#34455 (Ambiguous foreign keys syntax is accepted)
31
#
32
33
--disable_warnings
34
drop table if exists t_34455;
35
--enable_warnings
36
37
# 2 match clauses, illegal
38
--error ER_PARSE_ERROR
39
create table t_34455 (
40
  a int not null,
41
  foreign key (a) references t3 (a) match full match partial);
42
43
# match after on delete, illegal
44
--error ER_PARSE_ERROR
45
create table t_34455 (
46
  a int not null,
47
  foreign key (a) references t3 (a) on delete set default match full);
48
49
# match after on update, illegal
50
--error ER_PARSE_ERROR
51
create table t_34455 (
52
  a int not null,
53
  foreign key (a) references t3 (a) on update set default match full);
54
55
# 2 on delete clauses, illegal
56
--error ER_PARSE_ERROR
57
create table t_34455 (
58
  a int not null,
59
  foreign key (a) references t3 (a)
60
  on delete set default on delete set default);
61
62
# 2 on update clauses, illegal
63
--error ER_PARSE_ERROR
64
create table t_34455 (
65
  a int not null,
66
  foreign key (a) references t3 (a)
67
  on update set default on update set default);
68
69
create table t_34455 (a int not null);
70
71
# 2 match clauses, illegal
72
--error ER_PARSE_ERROR
73
alter table t_34455
74
  add foreign key (a) references t3 (a) match full match partial);
75
76
# match after on delete, illegal
77
--error ER_PARSE_ERROR
78
alter table t_34455
79
  add foreign key (a) references t3 (a) on delete set default match full);
80
81
# match after on update, illegal
82
--error ER_PARSE_ERROR
83
alter table t_34455
84
  add foreign key (a) references t3 (a) on update set default match full);
85
86
# 2 on delete clauses, illegal
87
--error ER_PARSE_ERROR
88
alter table t_34455
89
  add foreign key (a) references t3 (a)
90
  on delete set default on delete set default);
91
92
# 2 on update clauses, illegal
93
--error ER_PARSE_ERROR
94
alter table t_34455
95
  add foreign key (a) references t3 (a)
96
  on update set default on update set default);
97
98
drop table t_34455;
99