Project

General

Profile

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 19 jones
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 5 jones
DROP TABLE xml_documents;
21
DROP TABLE xml_attributes;
22
DROP TABLE xml_elements;
23 3 jones
24
/*
25
 * Elements -- table to store XML Elements
26
 */
27 5 jones
CREATE TABLE xml_elements (
28 3 jones
	nodeid		NUMBER(20),
29 10 jones
	parentnodeid	NUMBER(20),
30 3 jones
	nodename	VARCHAR2(2000),
31
	nodedata	VARCHAR2(2000),
32
	date_created	DATE,
33
	date_updated	DATE,
34 10 jones
   CONSTRAINT xml_elements_pk PRIMARY KEY (nodeid),
35
   CONSTRAINT xml_elements_parent_fk
36
		FOREIGN KEY (parentnodeid) REFERENCES xml_elements
37 3 jones
);
38
39 19 jones
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 3 jones
/*
51 5 jones
 * 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 3 jones
 * Attributes -- table to store XML Attributes
67
 */
68 5 jones
CREATE TABLE xml_attributes (
69 3 jones
	attributeid	NUMBER(20),
70
	nodeid		NUMBER(20),
71
	attributenumber	NUMBER(20),
72 19 jones
	attributename	VARCHAR2(256),
73 3 jones
	attributevalue	VARCHAR2(2000),
74
	date_created	DATE,
75
	date_updated	DATE,
76 5 jones
   CONSTRAINT xml_attributes_pk PRIMARY KEY (attributeid),
77
   CONSTRAINT xml_attributes_parent_node FOREIGN KEY (nodeid)
78 19 jones
		REFERENCES xml_elements,
79
   CONSTRAINT xml_attributes_uniq_attribute UNIQUE (nodeid,attributename)
80 3 jones
);
81 19 jones
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
/