1 |
2
|
jones
|
/*
|
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$'
|
10 |
|
|
*
|
11 |
|
|
*/
|
12 |
|
|
|
13 |
5
|
jones
|
/*
|
14 |
19
|
jones
|
* Drop all of the objects in proper order
|
15 |
2
|
jones
|
*/
|
16 |
20
|
jones
|
DROP SEQUENCE xml_nodes_id_seq;
|
17 |
|
|
DROP TRIGGER xml_nodes_before_insert;
|
18 |
5
|
jones
|
DROP TABLE xml_documents;
|
19 |
20
|
jones
|
DROP TABLE xml_nodes;
|
20 |
3
|
jones
|
|
21 |
|
|
/*
|
22 |
20
|
jones
|
* Nodes -- table to store XML Nodes (both elements and attributes)
|
23 |
3
|
jones
|
*/
|
24 |
20
|
jones
|
CREATE TABLE xml_nodes (
|
25 |
3
|
jones
|
nodeid NUMBER(20),
|
26 |
10
|
jones
|
parentnodeid NUMBER(20),
|
27 |
20
|
jones
|
nodetype VARCHAR2(2000),
|
28 |
3
|
jones
|
nodename VARCHAR2(2000),
|
29 |
|
|
nodedata VARCHAR2(2000),
|
30 |
|
|
date_created DATE,
|
31 |
|
|
date_updated DATE,
|
32 |
20
|
jones
|
CONSTRAINT xml_nodes_pk PRIMARY KEY (nodeid),
|
33 |
|
|
CONSTRAINT xml_nodes_parent_fk
|
34 |
|
|
FOREIGN KEY (parentnodeid) REFERENCES xml_nodes
|
35 |
3
|
jones
|
);
|
36 |
|
|
|
37 |
20
|
jones
|
CREATE SEQUENCE xml_nodes_id_seq;
|
38 |
19
|
jones
|
|
39 |
20
|
jones
|
CREATE TRIGGER xml_nodes_before_insert
|
40 |
|
|
BEFORE INSERT ON xml_nodes FOR EACH ROW
|
41 |
19
|
jones
|
BEGIN
|
42 |
20
|
jones
|
SELECT xml_nodes_id_seq.nextval
|
43 |
19
|
jones
|
INTO :new.nodeid
|
44 |
|
|
FROM dual;
|
45 |
|
|
END;
|
46 |
|
|
/
|
47 |
|
|
|
48 |
3
|
jones
|
/*
|
49 |
5
|
jones
|
* Documents -- table to store XML document catalog
|
50 |
|
|
*/
|
51 |
|
|
CREATE TABLE xml_documents (
|
52 |
|
|
docid NUMBER(20),
|
53 |
|
|
rootnodeid NUMBER(20),
|
54 |
|
|
docname VARCHAR2(1000),
|
55 |
|
|
doctype VARCHAR2(1000),
|
56 |
|
|
date_created DATE,
|
57 |
|
|
date_updated DATE,
|
58 |
|
|
CONSTRAINT xml_documents_pk PRIMARY KEY (docid),
|
59 |
|
|
CONSTRAINT xml_documents_root_fk
|
60 |
20
|
jones
|
FOREIGN KEY (rootnodeid) REFERENCES xml_nodes
|
61 |
5
|
jones
|
);
|