Index: src/xmltables_postgres.sql
===================================================================
--- src/xmltables_postgres.sql	(revision 754)
+++ src/xmltables_postgres.sql	(revision 755)
@@ -1,7 +1,8 @@
 /*
- * xmltables.sql -- Create or replace tables for storing XML in the db
+ * xmltables-postgres.sql
+ *             : Create or replace tables for storing XML in PostgreSQL
  *
- *      Purpose: creates tables needed for XML database
+ *      Purpose: creates tables needed for storing XML in PostgreSQL database
  * 
  *      Created: 08 May 2001 
  *       Author: John Harris
@@ -8,6 +9,8 @@
  * Organization: National Center for Ecological Analysis and Synthesis
  *    Copyright: 2000 Regents of the University of California and the
  *               National Center for Ecological Analysis and Synthesis
+ *  For Details: http://www.nceas.ucsb.edu/
+ *    File Info: '$Id$'
  *
  *	this is sql script does the same as the sql script named 
  *	xmltables.sql except that this script is to be use to 
@@ -79,6 +82,7 @@
  */
 CREATE INDEX xml_nodes_idx1 ON xml_nodes (rootnodeid);
 CREATE INDEX xml_nodes_idx2 ON xml_nodes (parentnodeid);
+CREATE INDEX xml_nodes_idx3 ON xml_nodes (nodename);
 CREATE SEQUENCE xml_nodes_id_seq;
 
 
Index: src/xmltables.sql
===================================================================
--- src/xmltables.sql	(revision 754)
+++ src/xmltables.sql	(revision 755)
@@ -91,6 +91,7 @@
  */
 CREATE INDEX xml_nodes_idx1 ON xml_nodes (rootnodeid);
 CREATE INDEX xml_nodes_idx2 ON xml_nodes (parentnodeid);
+CREATE INDEX xml_nodes_idx3 ON xml_nodes (nodename);
 
 CREATE SEQUENCE xml_nodes_id_seq;
 
Index: src/xmltables-sqlserver.sql
===================================================================
--- src/xmltables-sqlserver.sql	(revision 754)
+++ src/xmltables-sqlserver.sql	(revision 755)
@@ -1,10 +1,11 @@
 /*
- * xmltables.sql -- Create or replace tables for storing XML in the db
+ * xmltables-sqlserver.sql
+ *             : Create or replace tables for storing XML in MS SQL Server
  *
- *      Purpose: creates tables needed for XML database
+ *      Purpose: creates tables needed for storing XML in MS SQL Server database
  * 
- *      Created: 12 September 1999
- *       Author: Matt Jones
+ *      Created: 25 May 2001
+ *       Author: Jivka Bojilova
  * Organization: National Center for Ecological Analysis and Synthesis
  *    Copyright: 2000 Regents of the University of California and the
  *               National Center for Ecological Analysis and Synthesis
@@ -16,225 +17,437 @@
 /*
  * Drop all of the objects in proper order
  */
-/*set echo off*/
+if exists (select * from dbo.sysobjects 
+ where id = object_id(N'[dbo].[FK_xml_documents_xml_catalog]') 
+ and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[xml_documents] DROP CONSTRAINT FK_xml_documents_xml_catalog
+GO
 
-CREATE TRIGGER xml_replication_before_insert BEFORE INSERT
-ON xml_replication FOR EACH ROW
-BEGIN
-  SELECT xml_replication_id_seq.nextval
-    INTO :new.serverid
-    FROM dual;
-END;
-/
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[FK_xml_revisions_xml_catalog]')
+ and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[xml_revisions] DROP CONSTRAINT FK_xml_revisions_xml_catalog
+GO
 
-/*CREATE SEQUENCE xml_replication_id_seq;*/
-/*
- *Replication -- table to store servers that metacat is replicated to
- */
-CREATE TABLE xml_replication (
-  serverid      NUMBER(20),
-  server        VARCHAR2(512),
-  last_checked  DATE,
-  replicate     NUMBER(1), 
-  CONSTRAINT xml_replication_pk PRIMARY KEY (serverid)
-);  
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[FK_xml_access_xml_documents]')
+ and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[xml_access] DROP CONSTRAINT FK_xml_access_xml_documents
+GO
 
-INSERT INTO xml_replication (serverid, server, replicate) VALUES ('1', 'localhost', '0');
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[FK_xml_index_xml_documents]')
+ and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[xml_index] DROP CONSTRAINT FK_xml_index_xml_documents
+GO
 
-/* 
- * Nodes -- table to store XML Nodes (both elements and attributes)
- */
-CREATE TABLE xml_nodes (
-	nodeid		NUMBER(20),	-- the unique node id (pk)
-	nodeindex	NUMBER(10),	-- order of nodes within parent
-	nodetype	VARCHAR2(20),	-- type (DOCUMENT, COMMENT, PI,
-					-- ELEMENT, ATTRIBUTE, TEXT)
-	nodename	VARCHAR2(250),	-- the name of an element or attribute
-	nodedata	VARCHAR2(4000), -- the data for this node (e.g., 
-					-- for TEXT it is the content)
-	parentnodeid	NUMBER(20),	-- index of the parent of this node
-	rootnodeid	NUMBER(20),	-- index of the root node of this tree
-	docid		VARCHAR2(250),	-- index to the document id
-	date_created	DATE,
-	date_updated	DATE,
-   CONSTRAINT xml_nodes_pk PRIMARY KEY (nodeid),
-   CONSTRAINT xml_nodes_root_fk 
-		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
-   CONSTRAINT xml_nodes_parent_fk 
-		FOREIGN KEY (parentnodeid) REFERENCES xml_nodes
-);
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[FK_xml_relation_xml_documents]')
+ and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[xml_relation] DROP CONSTRAINT FK_xml_relation_xml_documents
+GO
 
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[FK_xml_documents_xml_nodes]')
+ and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[xml_documents] DROP CONSTRAINT FK_xml_documents_xml_nodes
+GO
+
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[FK_xml_index_xml_nodes]')
+ and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[xml_index] DROP CONSTRAINT FK_xml_index_xml_nodes
+GO
+
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[FK_xml_nodes_parentnodeid]')
+ and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[xml_nodes] DROP CONSTRAINT FK_xml_nodes_parentnodeid
+GO
+
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[FK_xml_nodes_rootnodeid]')
+ and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[xml_nodes] DROP CONSTRAINT FK_xml_nodes_rootnodeid
+GO
+
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[FK_xml_revisions_xml_nodes]')
+ and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[xml_revisions] DROP CONSTRAINT FK_xml_revisions_xml_nodes
+GO
+
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[FK_xml_documents_xml_replication]')
+ and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[xml_documents] 
+DROP CONSTRAINT FK_xml_documents_xml_replication
+GO
+
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[FK_xml_revisions_xml_replication]')
+ and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[xml_revisions] 
+DROP CONSTRAINT FK_xml_revisions_xml_replication
+GO
+
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[xml_access]')
+ and OBJECTPROPERTY(id, N'IsUserTable') = 1)
+drop table [dbo].[xml_access]
+GO
+
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[xml_catalog]')
+ and OBJECTPROPERTY(id, N'IsUserTable') = 1)
+drop table [dbo].[xml_catalog]
+GO
+
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[xml_documents]')
+ and OBJECTPROPERTY(id, N'IsUserTable') = 1)
+drop table [dbo].[xml_documents]
+GO
+
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[xml_index]')
+ and OBJECTPROPERTY(id, N'IsUserTable') = 1)
+drop table [dbo].[xml_index]
+GO
+
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[xml_nodes]')
+ and OBJECTPROPERTY(id, N'IsUserTable') = 1)
+drop table [dbo].[xml_nodes]
+GO
+
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[xml_relation]')
+ and OBJECTPROPERTY(id, N'IsUserTable') = 1)
+drop table [dbo].[xml_relation]
+GO
+
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[xml_replication]')
+ and OBJECTPROPERTY(id, N'IsUserTable') = 1)
+drop table [dbo].[xml_replication]
+GO
+
+if exists (select * from dbo.sysobjects
+ where id = object_id(N'[dbo].[xml_revisions]')
+ and OBJECTPROPERTY(id, N'IsUserTable') = 1)
+drop table [dbo].[xml_revisions]
+GO
+
 /* 
- * Indexes of rootnodeid & parentnodeid in xml_nodes
+ * ACL -- table to store ACL for XML documents by principals
  */
-CREATE INDEX xml_nodes_idx1 ON xml_nodes (rootnodeid);
-CREATE INDEX xml_nodes_idx2 ON xml_nodes (parentnodeid);
+CREATE TABLE [dbo].[xml_access] (
+  [docid] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [accessfileid] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [principal_name] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [permission] [int] NULL ,
+  [perm_type] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [perm_order] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [begin_time] [datetime] NULL ,
+  [end_time] [datetime] NULL ,
+  [ticket_count] [int] NULL 
+) ON [PRIMARY]
+GO
 
-CREATE SEQUENCE xml_nodes_id_seq;
-
 /* 
  * XML Catalog -- table to store all external sources for XML documents
  */
-CREATE TABLE xml_catalog (
-	catalog_id	NUMBER(20),	-- the id for this catalog entry
-	entry_type	VARCHAR2(500),	-- the type of this catalog entry
-					-- (e.g., DTD, XSD, XSL)
-	source_doctype	VARCHAR2(500),	-- the source public_id for transforms
-	target_doctype	VARCHAR2(500),	-- the target public_id for transforms
-	public_id	VARCHAR2(500),	-- the unique id for this type
-	system_id	VARCHAR2(1000),	-- the local location of the object
-   CONSTRAINT xml_catalog_pk PRIMARY KEY (catalog_id),
-   CONSTRAINT xml_catalog_uk UNIQUE 
-		(entry_type, source_doctype, target_doctype, public_id)
-);
+CREATE TABLE [dbo].[xml_catalog] (
+  [catalog_id] [bigint] IDENTITY (1, 1) NOT NULL ,
+  [entry_type] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [source_doctype] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [target_doctype] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [public_id] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [system_id] [varchar] (512) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
+) ON [PRIMARY]
+GO
 
-CREATE SEQUENCE xml_catalog_id_seq;
-
-CREATE TRIGGER xml_catalog_before_insert
-BEFORE INSERT ON xml_catalog FOR EACH ROW
-BEGIN
-  SELECT xml_catalog_id_seq.nextval
-    INTO :new.catalog_id
-    FROM dual;
-END;
-/
-
 /* 
  * Documents -- table to store XML documents
  */
-CREATE TABLE xml_documents (
-	docid		VARCHAR2(250),	-- the document id #
-	rootnodeid	NUMBER(20),	-- reference to root node of the DOM
-	docname		VARCHAR2(100),	-- usually the root element name
-	doctype		VARCHAR2(100),	-- public id indicating document type
-	user_owner	VARCHAR2(100),	-- the user owned the document
-	user_updated	VARCHAR2(100),	-- the user updated the document
-	server_location NUMBER(20),	-- the server on which this document resides
-	rev 		NUMBER(10) DEFAULT 1,--the revision number of the document
-	date_created	DATE,
-	date_updated	DATE,
-	public_access	NUMBER(1),	-- flag for public access
-        catalog_id      NUMBER(20),	-- reference to xml_catalog 
-   CONSTRAINT xml_documents_pk PRIMARY KEY (docid),
-   CONSTRAINT xml_documents_rep_fk
-    		FOREIGN KEY (server_location) REFERENCES xml_replication, 
-   CONSTRAINT xml_documents_root_fk 
-		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
-   CONSTRAINT xml_documents_catalog_fk 
-		FOREIGN KEY (catalog_id) REFERENCES xml_catalog
-);
+CREATE TABLE [dbo].[xml_documents] (
+  [docid] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
+  [rootnodeid] [bigint] NULL ,
+  [docname] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [doctype] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [user_owner] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [user_updated] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [server_location] [bigint] NULL ,
+  [rev] [int] NULL ,
+  [date_created] [datetime] NULL ,
+  [date_updated] [datetime] NULL ,
+  [public_access] [bit] NULL ,
+  [catalog_id] [bigint] NULL 
+) ON [PRIMARY]
+GO
 
 /* 
- * Index of <docid,doctype> in xml_document
+ * Index of Nodes -- table to store precomputed paths through tree for 
+ * quick searching in structured searches
  */
-CREATE INDEX xml_documents_idx1 ON xml_documents (docid, doctype);
+CREATE TABLE [dbo].[xml_index] (
+  [nodeid] [bigint] NOT NULL ,
+  [path] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
+  [docid] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [doctype] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [parentnodeid] [bigint] NULL 
+) ON [PRIMARY]
+GO
 
 /* 
- * Revised Documents -- table to store XML documents saved after an UPDATE
- *                    or DELETE
+ * Nodes -- table to store XML Nodes (both elements and attributes)
  */
-CREATE TABLE xml_revisions (
-	revisionid	NUMBER(20),	-- the revision number we are saving
-	docid		VARCHAR2(250),	-- the document id #
-	rootnodeid	NUMBER(20),	-- reference to root node of the DOM
-	docname		VARCHAR2(100),	-- usually the root element name
-	doctype		VARCHAR2(100),	-- public id indicating document type
-	user_owner	VARCHAR2(100),
-	user_updated	VARCHAR2(100),
-	server_location NUMBER(20),
-	rev		NUMBER(10),
-	date_created	DATE,
-	date_updated	DATE,
-	public_access	NUMBER(1),	-- flag for public access
-        catalog_id      NUMBER(20),	-- reference to xml_catalog 
-   CONSTRAINT xml_revisions_pk PRIMARY KEY (revisionid),
-   CONSTRAINT xml_revisions_rep_fk
-		FOREIGN KEY (server_location) REFERENCES xml_replication,
-   CONSTRAINT xml_revisions_root_fk 
-		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
-   CONSTRAINT xml_revisions_catalog_fk 
-		FOREIGN KEY (catalog_id) REFERENCES xml_catalog
-);
+CREATE TABLE [dbo].[xml_nodes] (
+  [nodeid] [bigint] IDENTITY (1, 1) NOT NULL ,
+  [nodeindex] [int] NULL ,
+  [nodetype] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [nodename] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [nodedata] [varchar] (4000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [parentnodeid] [bigint] NULL ,
+  [rootnodeid] [bigint] NULL ,
+  [docid] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [date_created] [datetime] NULL ,
+  [date_updated] [datetime] NULL 
+) ON [PRIMARY]
+GO
 
-CREATE SEQUENCE xml_revisions_id_seq;
-
-CREATE TRIGGER xml_revisions_before_insert
-BEFORE INSERT ON xml_revisions FOR EACH ROW
-BEGIN
-  SELECT xml_revisions_id_seq.nextval
-    INTO :new.revisionid
-    FROM dual;
-END;
-/
-
 /* 
- * ACL -- table to store ACL for XML documents by principals
+ * Relations -- table to store relations of form <subject,relationship,object>
  */
-CREATE TABLE xml_access (
-	docid		VARCHAR2(250),	-- the document id #
-	accessfileid	VARCHAR2(250),	-- the document id # for the access file
-	principal_name	VARCHAR2(100),	-- name of user, group, etc.
-	permission	NUMBER(1),	-- "read", "write", "all"
-	perm_type	VARCHAR2(32),	-- "allowed" or "denied"
-	perm_order	VARCHAR2(32),	-- "allow first" or "deny first"
-	begin_time	DATE,		-- the time that permission begins
-	end_time	DATE,		-- the time that permission ends
-	ticket_count	NUMBER(5),	-- ticket counter for that permission
-   CONSTRAINT xml_access_ck CHECK (begin_time < end_time),
-   CONSTRAINT xml_access_accessfileid_fk 
-		FOREIGN KEY (accessfileid) REFERENCES xml_documents
-);
+CREATE TABLE [dbo].[xml_relation] (
+  [relationid] [bigint] IDENTITY (1, 1) NOT NULL ,
+  [docid] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [packagetype] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [subject] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
+  [subdoctype] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [relationship] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
+  [object] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
+  [objdoctype] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
+) ON [PRIMARY]
+GO
 
 /* 
- * Index of Nodes -- table to store precomputed paths through tree for 
- * quick searching in structured searches
+ * Replication -- table to store servers that metacat is replicated to
  */
-CREATE TABLE xml_index (
-	nodeid		NUMBER(20),	-- the unique node id
-	path		VARCHAR2(200),	-- precomputed path through tree
-	docid		VARCHAR2(250),	-- index to the document id
-	doctype		VARCHAR2(100),	-- public id indicating document type
-        parentnodeid    NUMBER(20),     -- id of the parent of the node represented
-					-- by this row
-   CONSTRAINT xml_index_pk PRIMARY KEY (nodeid,path),
-   CONSTRAINT xml_index_nodeid_fk FOREIGN KEY (nodeid) REFERENCES xml_nodes,
-   CONSTRAINT xml_index_docid_fk 
-		FOREIGN KEY (docid) REFERENCES xml_documents
-);
+CREATE TABLE [dbo].[xml_replication] (
+  [serverid] [bigint] IDENTITY (1, 1) NOT NULL ,
+  [server] [varchar] (512) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [last_checked] [datetime] NULL ,
+  [replicate] [bit] NULL 
+) ON [PRIMARY]
+GO
 
 /* 
- * Index of the paths in xml_index 
+ * Revised Documents -- table to store XML documents saved after an UPDATE
+ *                    or DELETE
  */
-CREATE INDEX xml_index_idx1 ON xml_index (path);
+CREATE TABLE [dbo].[xml_revisions] (
+  [revisionid] [bigint] IDENTITY (1, 1) NOT NULL ,
+  [docid] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [rootnodeid] [bigint] NULL ,
+  [docname] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [doctype] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [user_owner] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [user_updated] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+  [server_location] [bigint] NULL ,
+  [rev] [int] NULL ,
+  [date_created] [datetime] NULL ,
+  [date_updated] [datetime] NULL ,
+  [public_access] [bit] NULL ,
+  [catalog_id] [bigint] NULL 
+) ON [PRIMARY]
+GO
 
 /* 
- * Sequence to get uniqueID for Accession #
+ * Constraints and indexes
  */
-CREATE SEQUENCE accnum_uniqueid_seq;
+ALTER TABLE [dbo].[xml_catalog] WITH NOCHECK ADD 
+	CONSTRAINT [PK_xml_catalog] PRIMARY KEY  CLUSTERED 
+	(
+		[catalog_id]
+	)  ON [PRIMARY] 
+GO
 
-CREATE TABLE xml_relation (
-	relationid    NUMBER(20) PRIMARY KEY, -- unique id
-	docid         VARCHAR2(250) ,         -- the docid of the package file
-	                                      -- that this relation came from
-        packagetype   VARCHAR2(250),          -- the type of the package
-	subject       VARCHAR2(512) NOT NULL, -- the subject of the relation
-	subdoctype    VARCHAR2(128),         	-- the doctype of the subject
-	relationship  VARCHAR2(128)  NOT NULL,-- the relationship type
-	object        VARCHAR2(512) NOT NULL, -- the object of the relation
-	objdoctype    VARCHAR2(128),          -- the doctype of the object
-	CONSTRAINT xml_relation_uk UNIQUE (subject, relationship, object),
-	CONSTRAINT xml_relation_docid_fk 
-		FOREIGN KEY (docid) REFERENCES xml_documents
-  );
+ALTER TABLE [dbo].[xml_documents] WITH NOCHECK ADD 
+	CONSTRAINT [PK_xml_documents] PRIMARY KEY  CLUSTERED 
+	(
+		[docid]
+	)  ON [PRIMARY] 
+GO
 
-CREATE SEQUENCE xml_relation_id_seq;
-  
-CREATE TRIGGER xml_relation_before_insert
-BEFORE INSERT ON xml_relation FOR EACH ROW
-BEGIN
-  SELECT xml_relation_id_seq.nextval
-    INTO :new.relationid
-    FROM dual;
-END;
-/
+ALTER TABLE [dbo].[xml_index] WITH NOCHECK ADD 
+	CONSTRAINT [PK_xml_index] PRIMARY KEY  CLUSTERED 
+	(
+		[nodeid],
+		[path]
+	)  ON [PRIMARY] 
+GO
 
+ALTER TABLE [dbo].[xml_nodes] WITH NOCHECK ADD 
+	CONSTRAINT [PK_xml_nodes] PRIMARY KEY  CLUSTERED 
+	(
+		[nodeid]
+	)  ON [PRIMARY] 
+GO
+
+ALTER TABLE [dbo].[xml_relation] WITH NOCHECK ADD 
+	CONSTRAINT [PK_xml_relation] PRIMARY KEY  CLUSTERED 
+	(
+		[relationid]
+	)  ON [PRIMARY] 
+GO
+
+ALTER TABLE [dbo].[xml_replication] WITH NOCHECK ADD 
+	CONSTRAINT [PK_xml_replication] PRIMARY KEY  CLUSTERED 
+	(
+		[serverid]
+	)  ON [PRIMARY] 
+GO
+
+ALTER TABLE [dbo].[xml_revisions] WITH NOCHECK ADD 
+	CONSTRAINT [PK_xml_revisions] PRIMARY KEY  CLUSTERED 
+	(
+		[revisionid]
+	)  ON [PRIMARY] 
+GO
+
+ALTER TABLE [dbo].[xml_access] WITH NOCHECK ADD 
+	CONSTRAINT [CK_xml_access] CHECK ([begin_time] < [end_time])
+GO
+
+ALTER TABLE [dbo].[xml_catalog] WITH NOCHECK ADD 
+	CONSTRAINT [IX_xml_catalog] UNIQUE  NONCLUSTERED 
+	(
+		[entry_type],
+		[source_doctype],
+		[target_doctype],
+		[public_id]
+	)  ON [PRIMARY] 
+GO
+
+ALTER TABLE [dbo].[xml_documents] WITH NOCHECK ADD 
+	CONSTRAINT [DF_xml_documents_rev] DEFAULT (1) FOR [rev]
+GO
+
+ALTER TABLE [dbo].[xml_relation] WITH NOCHECK ADD 
+	CONSTRAINT [IX_xml_relation] UNIQUE  NONCLUSTERED 
+	(
+		[subject],
+		[relationship],
+		[object]
+	)  ON [PRIMARY] 
+GO
+
+ CREATE  INDEX [IX_xml_documents] ON [dbo].[xml_documents]([docid], [doctype])
+                                                                    ON [PRIMARY]
+GO
+
+ CREATE  INDEX [IX_xml_index] ON [dbo].[xml_index]([path]) ON [PRIMARY]
+GO
+
+ CREATE  INDEX [IX1_xml_nodes] ON [dbo].[xml_nodes]([rootnodeid]) ON [PRIMARY]
+GO
+
+ CREATE  INDEX [IX2_xml_nodes] ON [dbo].[xml_nodes]([parentnodeid]) ON [PRIMARY]
+GO
+
+ CREATE  INDEX [IX3_xml_nodes] ON [dbo].[xml_nodes]([nodename]) ON [PRIMARY]
+GO
+
+ALTER TABLE [dbo].[xml_access] ADD 
+	CONSTRAINT [FK_xml_access_xml_documents] FOREIGN KEY 
+	(
+		[accessfileid]
+	) REFERENCES [dbo].[xml_documents] (
+		[docid]
+	)
+GO
+
+ALTER TABLE [dbo].[xml_documents] ADD 
+	CONSTRAINT [FK_xml_documents_xml_catalog] FOREIGN KEY 
+	(
+		[catalog_id]
+	) REFERENCES [dbo].[xml_catalog] (
+		[catalog_id]
+	),
+	CONSTRAINT [FK_xml_documents_xml_nodes] FOREIGN KEY 
+	(
+		[rootnodeid]
+	) REFERENCES [dbo].[xml_nodes] (
+		[nodeid]
+	),
+	CONSTRAINT [FK_xml_documents_xml_replication] FOREIGN KEY 
+	(
+		[server_location]
+	) REFERENCES [dbo].[xml_replication] (
+		[serverid]
+	)
+GO
+
+ALTER TABLE [dbo].[xml_index] ADD 
+	CONSTRAINT [FK_xml_index_xml_documents] FOREIGN KEY 
+	(
+		[docid]
+	) REFERENCES [dbo].[xml_documents] (
+		[docid]
+	),
+	CONSTRAINT [FK_xml_index_xml_nodes] FOREIGN KEY 
+	(
+		[nodeid]
+	) REFERENCES [dbo].[xml_nodes] (
+		[nodeid]
+	)
+GO
+
+ALTER TABLE [dbo].[xml_nodes] ADD 
+	CONSTRAINT [FK_xml_nodes_parentnodeid] FOREIGN KEY 
+	(
+		[parentnodeid]
+	) REFERENCES [dbo].[xml_nodes] (
+		[nodeid]
+	),
+	CONSTRAINT [FK_xml_nodes_rootnodeid] FOREIGN KEY 
+	(
+		[rootnodeid]
+	) REFERENCES [dbo].[xml_nodes] (
+		[nodeid]
+	)
+GO
+
+ALTER TABLE [dbo].[xml_relation] ADD 
+	CONSTRAINT [FK_xml_relation_xml_documents] FOREIGN KEY 
+	(
+		[docid]
+	) REFERENCES [dbo].[xml_documents] (
+		[docid]
+	)
+GO
+
+ALTER TABLE [dbo].[xml_revisions] ADD 
+	CONSTRAINT [FK_xml_revisions_xml_catalog] FOREIGN KEY 
+	(
+		[catalog_id]
+	) REFERENCES [dbo].[xml_catalog] (
+		[catalog_id]
+	),
+	CONSTRAINT [FK_xml_revisions_xml_nodes] FOREIGN KEY 
+	(
+		[rootnodeid]
+	) REFERENCES [dbo].[xml_nodes] (
+		[nodeid]
+	),
+	CONSTRAINT [FK_xml_revisions_xml_r
+eplication] FOREIGN KEY 
+	(
+		[server_location]
+	) REFERENCES [dbo].[xml_replication] (
+		[serverid]
+	)
+GO
+
