~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
DROP TABLE IF EXISTS t1,t2,t3;
CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id, id),
FOREIGN KEY (t1_id) REFERENCES t1(id)  ON DELETE CASCADE,
FOREIGN KEY (t1_id) REFERENCES t1(id)  ON UPDATE CASCADE) ENGINE=INNODB;
CREATE TABLE t3 (id INT PRIMARY KEY, t2_id INT, INDEX par_ind (t2_id),
FOREIGN KEY (id, t2_id) REFERENCES t2(t1_id, id)  ON DELETE CASCADE) ENGINE=INNODB;
select * from data_dictionary.indexes where TABLE_SCHEMA= "test";
TABLE_SCHEMA	TABLE_NAME	INDEX_NAME	IS_USED_IN_PRIMARY	IS_UNIQUE	IS_NULLABLE	KEY_LENGTH	INDEX_TYPE	INDEX_COMMENT
test	t1	PRIMARY	YES	YES	NO	4	BTREE	NULL
test	t2	PRIMARY	YES	YES	NO	4	BTREE	NULL
test	t2	par_ind	NO	NO	YES	8	BTREE	NULL
test	t3	PRIMARY	YES	YES	NO	4	BTREE	NULL
test	t3	id	NO	NO	YES	8	BTREE	NULL
test	t3	par_ind	NO	NO	YES	4	BTREE	NULL
drop table t3, t2, t1;
CREATE TABLE t1(a1 INT NOT NULL, a2 INT NOT NULL,
PRIMARY KEY(a1, a2)) ENGINE=INNODB;
CREATE TABLE t2(b1 INT, b2 INT, INDEX (b1, b2),
CONSTRAINT A1
FOREIGN KEY (b1, b2) REFERENCES t1(a1, a2)
ON UPDATE CASCADE ON DELETE NO ACTION) ENGINE=INNODB;
CREATE TABLE t3(b1 INT, b2 INT, INDEX t3_indx (b1, b2),
CONSTRAINT A2
FOREIGN KEY (b1, b2) REFERENCES t2(b1, b2)
ON UPDATE SET NULL ON DELETE RESTRICT) ENGINE=INNODB;
CREATE TABLE t4(b1 INT, b2 INT, UNIQUE KEY t4_ukey (b1, b2),
CONSTRAINT A3
FOREIGN KEY (b1, b2) REFERENCES t3(b1, b2)
ON UPDATE NO ACTION ON DELETE SET NULL) ENGINE=INNODB;
CREATE TABLE t5(b1 INT, b2 INT, INDEX (b1, b2),
CONSTRAINT A4
FOREIGN KEY (b1, b2) REFERENCES t4(b1, b2)
ON UPDATE RESTRICT ON DELETE CASCADE) ENGINE=INNODB;
drop tables t5, t4, t3, t2, t1;
create database `db-1`;
use `db-1`;
create table `t-2` (
id int not null auto_increment,
primary key (id)
) engine=innodb;
create table `t-1` (
id int not null auto_increment,
idtype int not null,
primary key (id),
key fk_t1_1 (idtype),
constraint fk_t1_1 foreign key (idtype) references `t-2` (id)
) engine=innodb;
use test;
drop database `db-1`;
create table t1(id int primary key) engine = Innodb;
create table t2(pid int, foreign key (pid) references t1(id)) engine = Innodb;
set foreign_key_checks = 0;
drop table t1;
drop table t2;
set foreign_key_checks = 1;