Ticket #3045: Trac_3054_Data.sql

File Trac_3054_Data.sql, 8.2 KB (added by Benjamin Haag, 22 months ago)

SQL used to populate new tables.

Line 
1USE gringlobal
2GO
3
4--==================================================================================================
5-- ORDER
6--==================================================================================================
7DELETE FROM taxonomy_classification
8GO
9
10INSERT INTO taxonomy_classification (classification_name)
11(SELECT DISTINCT suprafamily_rank_name FROM taxonomy_family WHERE suprafamily_rank_name IS NOT NULL)
12
13--==================================================================================================
14-- FAMILY
15--==================================================================================================
16DELETE FROM taxonomy_family_parent
17GO
18
19SET IDENTITY_INSERT taxonomy_family_parent ON
20INSERT INTO
21 taxonomy_family_parent
22 (taxonomy_family_parent_id,
23 accepted_taxonomy_family_map_id,
24 type_taxonomy_genus_id,
25 taxonomy_classification_id,
26 family_name,
27 family_authority,
28 alternate_name,
29 family_type_code,
30 note,
31 created_by,
32 created_date,
33 modified_by,
34 modified_date,
35 owned_by,
36 owned_date)
37SELECT taxonomy_family_id AS taxonomy_family_parent_id
38 , current_taxonomy_family_id AS accepted_taxonomy_family_map_id
39 , type_taxonomy_genus_id
40 , (SELECT taxonomy_classification_id FROM taxonomy_classification WHERE classification_name = suprafamily_rank_name) AS taxonomy_classification_id
41 , family_name
42 , family_authority
43 , alternate_name
44 , CASE WHEN family_type_code IS NOT NULL THEN family_type_code
45 WHEN NOTE LIKE 'dicot%' THEN 'DICOT'
46 WHEN NOTE LIKE 'monocot%' THEN 'MONOCOT'
47 WHEN NOTE LIKE 'fern%' THEN 'DICOT'
48 WHEN NOTE LIKE 'gymnosperm%' THEN 'GYMNOSPERM'
49 WHEN NOTE LIKE 'virus%' THEN 'VIRUS'
50 WHEN NOTE LIKE 'bacterial%' THEN 'BACTERIAL'
51 ELSE NULL
52 END as family_type_code
53 , note, created_by, created_date, modified_by, modified_date, owned_by, owned_date
54FROM
55 taxonomy_family
56WHERE
57 COALESCE(subfamily_name, tribe_name, subtribe_name) IS NULL
58SET IDENTITY_INSERT taxonomy_family_parent OFF
59
60/*
61==================================================================================================
62taxonomy_subfamily
63==================================================================================================
64*/
65DELETE FROM taxonomy_subfamily
66
67SET IDENTITY_INSERT taxonomy_subfamily ON
68INSERT INTO taxonomy_subfamily
69(
70 taxonomy_subfamily_id,
71 accepted_taxonomy_family_map_id,
72 type_taxonomy_genus_id,
73 taxonomy_family_parent_id,
74 subfamily_name,
75 subfamily_authority,
76 note,
77 created_by,
78 created_date,
79 modified_by,
80 modified_date,
81 owned_by,
82 owned_date
83)
84SELECT taxonomy_family_id AS taxonomy_subfamily_id
85 , current_taxonomy_family_id AS accepted_taxonomy_family_map_id
86 , type_taxonomy_genus_id
87 , (SELECT taxonomy_family_parent_id FROM taxonomy_family_parent WHERE family_name = tf.family_name) AS taxonomy_family_parent_id
88 , subfamily_name
89 , family_authority as subfamily_authority
90 , note, created_by, created_date, modified_by, modified_date, owned_by, owned_date
91FROM taxonomy_family tf
92WHERE subfamily_name is not null AND coalesce(tribe_name, subtribe_name) IS NULL
93SET IDENTITY_INSERT taxonomy_subfamily OFF
94
95/*
96==================================================================================================
97taxonomy_tribe
98==================================================================================================
99*/
100DELETE FROM taxonomy_tribe
101GO
102
103SET IDENTITY_INSERT taxonomy_tribe ON
104INSERT INTO taxonomy_tribe
105(
106 taxonomy_tribe_id,
107 accepted_taxonomy_family_map_id,
108 type_taxonomy_genus_id,
109 taxonomy_family_parent_id,
110 taxonomy_subfamily_id,
111 tribe_name,
112 tribe_authority,
113 note,
114 created_by,
115 created_date,
116 modified_by,
117 modified_date,
118 owned_by,
119 owned_date
120)
121(SELECT taxonomy_family_id AS taxonomy_tribe_id
122 , current_taxonomy_family_id AS accepted_taxonomy_family_map_id
123 , type_taxonomy_genus_id
124 , (SELECT taxonomy_family_parent_id FROM taxonomy_family_parent WHERE family_name = tf.family_name) AS taxonomy_family_parent_id
125 , (SELECT taxonomy_subfamily_id FROM taxonomy_subfamily
126 WHERE subfamily_name = tf.subfamily_name AND taxonomy_family_parent_id = (SELECT taxonomy_family_parent_id FROM taxonomy_family_parent WHERE family_name = tf.family_name)
127 ) AS taxonomy_subfamily_id
128 , tribe_name
129 , family_authority as tribe_authority
130 , note, created_by, created_date, modified_by, modified_date, owned_by, owned_date
131FROM taxonomy_family tf
132WHERE tribe_name is not null AND subtribe_name IS NULL
133)
134SET IDENTITY_INSERT taxonomy_tribe OFF
135
136/*
137==================================================================================================
138taxonomy_subtribe
139==================================================================================================
140*/
141
142DELETE FROM taxonomy_subtribe
143GO
144
145SET IDENTITY_INSERT taxonomy_subtribe ON
146INSERT INTO taxonomy_subtribe
147(
148 taxonomy_subtribe_id,
149 accepted_taxonomy_family_map_id,
150 type_taxonomy_genus_id,
151 taxonomy_family_parent_id,
152 taxonomy_subfamily_id,
153 taxonomy_tribe_id,
154 subtribe_name,
155 subtribe_authority,
156 note,
157 created_by,
158 created_date ,
159 modified_by,
160 modified_date ,
161 owned_by,
162 owned_date
163)
164(SELECT taxonomy_family_id AS taxonomy_subtribe_id
165 , current_taxonomy_family_id AS accepted_taxonomy_family_map_id
166 , type_taxonomy_genus_id
167 , (SELECT taxonomy_family_parent_id FROM taxonomy_family_parent WHERE family_name = tf.family_name) AS taxonomy_family_parent_id
168 , (SELECT taxonomy_subfamily_id FROM taxonomy_subfamily
169 WHERE subfamily_name = tf.subfamily_name AND taxonomy_family_parent_id = (SELECT taxonomy_family_parent_id FROM taxonomy_family_parent WHERE family_name = tf.family_name)
170 ) AS taxonomy_subfamily_id
171 , (SELECT taxonomy_tribe_id FROM taxonomy_tribe
172 WHERE tribe_name = tf.tribe_name AND taxonomy_family_parent_id = (SELECT taxonomy_family_parent_id FROM taxonomy_family_parent WHERE family_name = tf.family_name)
173 ) AS taxonomy_tribe_id
174 , subtribe_name
175 , family_authority as subtribe_authority
176 , note, created_by, created_date, modified_by, modified_date, owned_by, owned_date
177FROM taxonomy_family tf
178WHERE subtribe_name IS NOT NULL
179)
180SET IDENTITY_INSERT taxonomy_subtribe OFF
181
182/*
183==================================================================================================
184taxonomy_family_map
185==================================================================================================
186*/
187DELETE FROM taxonomy_family_map
188GO
189
190SET IDENTITY_INSERT taxonomy_family_map ON
191INSERT INTO taxonomy_family_map
192(
193 taxonomy_family_map_id,
194 taxonomy_family_map_accepted_id,
195 authority,
196 taxonomy_family_parent_id,
197 taxonomy_subfamily_id,
198 taxonomy_tribe_id,
199 taxonomy_subtribe_id,
200 created_by,
201 created_date,
202 modified_by,
203 modified_date,
204 owned_by,
205 owned_date
206)
207(
208SELECT
209 taxonomy_family_parent_id as taxonomy_family_map_id,
210 accepted_taxonomy_family_map_id
211 ,family_authority
212 ,taxonomy_family_parent_id
213 , NULL AS taxonomy_subfamily_id
214 , NULL AS taxonomy_tribe_id
215 , NULL AS taxonomy_subtribe_id
216 , created_by, created_date, modified_by, modified_date, owned_by, owned_date
217FROM
218 taxonomy_family_parent
219UNION
220SELECT
221 taxonomy_subfamily_id AS taxonomy_family_map_id
222 ,accepted_taxonomy_family_map_id
223 ,subfamily_authority
224 , taxonomy_family_parent_id
225 ,taxonomy_subfamily_id
226 , NULL AS taxonomy_tribe_id
227 , NULL AS taxonomy_subtribe_id
228 , created_by, created_date, modified_by, modified_date, owned_by, owned_date
229FROM
230 taxonomy_subfamily
231UNION
232SELECT
233 taxonomy_tribe_id AS taxonomy_family_map_id
234 ,accepted_taxonomy_family_map_id
235 ,tribe_authority
236 , taxonomy_family_parent_id
237 ,taxonomy_subfamily_id
238 ,taxonomy_tribe_id
239 , NULL AS taxonomy_subtribe_id
240 , created_by, created_date, modified_by, modified_date, owned_by, owned_date
241FROM
242 taxonomy_tribe
243UNION
244SELECT
245 taxonomy_subtribe_id AS taxonomy_family_map_id
246 ,accepted_taxonomy_family_map_id
247 ,subtribe_authority
248 , taxonomy_family_parent_id,
249 taxonomy_subfamily_id,
250 taxonomy_tribe_id,
251 taxonomy_subtribe_id
252 , created_by, created_date, modified_by, modified_date, owned_by, owned_date
253FROM
254 taxonomy_subtribe)
255SET IDENTITY_INSERT taxonomy_family_map OFF
256