1
|
/*
|
2
|
* xmltables.sql -- Create or replace tables for storing XML in the db
|
3
|
*
|
4
|
* Purpose: creates tables needed for XML database
|
5
|
*
|
6
|
* Created: 12 September 1999
|
7
|
* Author: Matt Jones
|
8
|
* Organization: National Center for Ecological Analysis and Synthesis
|
9
|
* Version: '$Id: xmltables.sql 19 2000-04-11 17:57:28Z jones $'
|
10
|
*
|
11
|
*/
|
12
|
|
13
|
/*
|
14
|
* Drop all of the objects in proper order
|
15
|
*/
|
16
|
DROP SEQUENCE xml_attributes_id_seq;
|
17
|
DROP TRIGGER xml_attributes_before_insert;
|
18
|
DROP SEQUENCE xml_elements_id_seq;
|
19
|
DROP TRIGGER xml_elements_before_insert;
|
20
|
DROP TABLE xml_documents;
|
21
|
DROP TABLE xml_attributes;
|
22
|
DROP TABLE xml_elements;
|
23
|
|
24
|
/*
|
25
|
* Elements -- table to store XML Elements
|
26
|
*/
|
27
|
CREATE TABLE xml_elements (
|
28
|
nodeid NUMBER(20),
|
29
|
parentnodeid NUMBER(20),
|
30
|
nodename VARCHAR2(2000),
|
31
|
nodedata VARCHAR2(2000),
|
32
|
date_created DATE,
|
33
|
date_updated DATE,
|
34
|
CONSTRAINT xml_elements_pk PRIMARY KEY (nodeid),
|
35
|
CONSTRAINT xml_elements_parent_fk
|
36
|
FOREIGN KEY (parentnodeid) REFERENCES xml_elements
|
37
|
);
|
38
|
|
39
|
CREATE SEQUENCE xml_elements_id_seq;
|
40
|
|
41
|
CREATE TRIGGER xml_elements_before_insert
|
42
|
BEFORE INSERT ON xml_elements FOR EACH ROW
|
43
|
BEGIN
|
44
|
SELECT xml_elements_id_seq.nextval
|
45
|
INTO :new.nodeid
|
46
|
FROM dual;
|
47
|
END;
|
48
|
/
|
49
|
|
50
|
/*
|
51
|
* Documents -- table to store XML document catalog
|
52
|
*/
|
53
|
CREATE TABLE xml_documents (
|
54
|
docid NUMBER(20),
|
55
|
rootnodeid NUMBER(20),
|
56
|
docname VARCHAR2(1000),
|
57
|
doctype VARCHAR2(1000),
|
58
|
date_created DATE,
|
59
|
date_updated DATE,
|
60
|
CONSTRAINT xml_documents_pk PRIMARY KEY (docid),
|
61
|
CONSTRAINT xml_documents_root_fk
|
62
|
FOREIGN KEY (rootnodeid) REFERENCES xml_elements
|
63
|
);
|
64
|
|
65
|
/*
|
66
|
* Attributes -- table to store XML Attributes
|
67
|
*/
|
68
|
CREATE TABLE xml_attributes (
|
69
|
attributeid NUMBER(20),
|
70
|
nodeid NUMBER(20),
|
71
|
attributenumber NUMBER(20),
|
72
|
attributename VARCHAR2(256),
|
73
|
attributevalue VARCHAR2(2000),
|
74
|
date_created DATE,
|
75
|
date_updated DATE,
|
76
|
CONSTRAINT xml_attributes_pk PRIMARY KEY (attributeid),
|
77
|
CONSTRAINT xml_attributes_parent_node FOREIGN KEY (nodeid)
|
78
|
REFERENCES xml_elements,
|
79
|
CONSTRAINT xml_attributes_uniq_attribute UNIQUE (nodeid,attributename)
|
80
|
);
|
81
|
|
82
|
CREATE SEQUENCE xml_attributes_id_seq;
|
83
|
|
84
|
CREATE TRIGGER xml_attributes_before_insert
|
85
|
BEFORE INSERT ON xml_attributes FOR EACH ROW
|
86
|
BEGIN
|
87
|
SELECT xml_attributes_id_seq.nextval
|
88
|
INTO :new.attributeid
|
89
|
FROM dual;
|
90
|
END;
|
91
|
/
|
92
|
|