45997ef14362c8c0ee646d372843997e8f38e031
[dbsrgits/SQL-Translator.git] / t / data / pgsql / turnkey.sql
1 -- 1 single FK import, data table
2 create table a (
3         a_id serial not null,
4         primary key (a_id),
5         b_id int not null,
6         foreign key (b_id) references b (b_id),
7         name text
8 );
9
10 -- standalone, data table
11 create table b (
12         b_id serial not null,
13         primary key (b_id),
14         name text
15 );
16
17 -- 1 single FK import, link table between 'a' and 'b'
18 create table a_b (
19         a_b_id serial not null,
20         primary key (a_b_id),
21         a_id int not null,
22         foreign key (a_id) references a (a_id),
23         b_id int not null,
24         foreign key (b_id) references b (b_id)
25 );
26
27 -- 1 single FK import, data table
28 create table c (
29         c_id serial not null,
30         primary key (c_id),
31         b_id int not null,
32         foreign key (b_id) references b (b_id),
33         name text
34 );
35
36 -- 1 single FK import, data table
37 create table d (
38         d_id serial not null,
39         primary key (d_id),
40         c_id int not null,
41         foreign key (c_id) references c (c_id),
42         name text
43 );
44
45 -- standalone, data table
46 create table e (
47         e_id serial not null,
48         primary key (e_id),
49         name text
50 );
51
52 -- 2 single FK import, link table between 'c' and 'e'
53 create table c_e (
54         c_e_id serial not null,
55         primary key (c_e_id),
56         c_id int not null,
57         foreign key (c_id) references c (c_id),
58         e_id int not null,
59         foreign key (e_id) references e (e_id)
60 );
61
62 -- 1 triple FK import, link table between 'e', 'e', and 'e'
63 create table f (
64         f_id serial not null,
65         primary key (f_id),
66         e1_id int not null,
67         foreign key (e1_id) references e (e_id),
68         e2_id int not null,
69         foreign key (e2_id) references e (e_id),
70         e3_id int not null,
71         foreign key (e3_id) references e (e_id)
72 );
73
74 -- 1 single FK import, 1 double FK import, link table between 'a', 'e', and 'e'
75 create table g (
76         g_id serial not null,
77         primary key (g_id),
78         a_id int not null,
79         foreign key (a_id) references a (a_id),
80         e1_id int not null,
81         foreign key (e1_id) references e (e_id),
82         e2_id int not null,
83         foreign key (e2_id) references e (e_id)
84 );
85
86 -- 1 double FK import, 1 triple FK import, link table between 'a', 'a', 'g', 'g', and 'g'
87 create table h (
88         h_id serial not null,
89         primary key (h_id),
90         a1_id int not null,
91         foreign key (a1_id) references a (a_id),
92         a2_id int not null,
93         foreign key (a2_id) references a (a_id),
94         g1_id int not null,
95         foreign key (g1_id) references g (g_id),
96         g2_id int not null,
97         foreign key (g2_id) references g (g_id),
98         g3_id int not null,
99         foreign key (g3_id) references g (g_id)
100 );
101