Index: src/xmltables_postgres.sql
===================================================================
--- src/xmltables_postgres.sql	(revision 758)
+++ src/xmltables_postgres.sql	(revision 759)
@@ -30,6 +30,7 @@
 DROP SEQUENCE xml_replication_id_seq;
 DROP SEQUENCE accnum_uniqueid_seq;
 DROP SEQUENCE xml_documents_id_seq;
+DROP SEQUENCE accession_number_id_seq;
 
 DROP TABLE xml_index;
 DROP TABLE xml_access;
@@ -39,6 +40,7 @@
 DROP TABLE xml_nodes;
 DROP TABLE xml_replication;
 DROP TABLE xml_catalog;
+DROP TABLE accession_number;
 
 /*
  *Replication -- table to store servers that metacat is replicated to
@@ -45,8 +47,8 @@
  */
 CREATE SEQUENCE xml_replication_id_seq;
 CREATE TABLE xml_replication (
-  serverid     INT8  default nextval('xml_replication_id_seq'), 
-  server        VARCHAR(512),
+  serverid	INT8  default nextval('xml_replication_id_seq'), 
+  server	VARCHAR(512),
   last_checked  DATE,
   replicate     INT8, 
   CONSTRAINT xml_replication_pk PRIMARY KEY (serverid)
@@ -57,8 +59,10 @@
 /* 
  * Nodes -- table to store XML Nodes (both elements and attributes)
  */
+CREATE SEQUENCE xml_nodes_id_seq;
 CREATE TABLE xml_nodes (
-	nodeid		INT8, 		-- the unique node id (pk)
+	nodeid		INT8 default nextval('xml_nodes_id_seq'),
+					-- the unique node id (pk)
 	nodeindex	INT8,		-- order of nodes within parent
 	nodetype	VARCHAR(20),	-- type (DOCUMENT, COMMENT, PI,
 					-- ELEMENT, ATTRIBUTE, TEXT)
@@ -76,22 +80,20 @@
    CONSTRAINT xml_nodes_parent_fk 
 		FOREIGN KEY (parentnodeid) REFERENCES xml_nodes
 );
-
 /* 
- * Indexes of rootnodeid & parentnodeid in xml_nodes
+ * Indexes of rootnodeid, parentnodeid, and nodename in xml_nodes
  */
 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;
 
-
 /* 
  * XML Catalog -- table to store all external sources for XML documents
  */
 CREATE SEQUENCE xml_catalog_id_seq;
 CREATE TABLE xml_catalog (
-	catalog_id INT8 default nextval('xml_catalog_id_seq'), -- the id for this catalog entry
+	catalog_id	INT8 default nextval('xml_catalog_id_seq'),
+                                        -- the id for this catalog entry
 	entry_type	VARCHAR(500),	-- the type of this catalog entry
 					-- (e.g., DTD, XSD, XSL)
 	source_doctype	VARCHAR(500),	-- the source public_id for transforms
@@ -99,10 +101,10 @@
 	public_id	VARCHAR(500),	-- the unique id for this type
 	system_id	VARCHAR(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)
+   CONSTRAINT xml_catalog_uk UNIQUE  
+              (entry_type, source_doctype, target_doctype, public_id)
 );
 
-
 /* 
  * Sequence to get uniqueID for Accession #
  */
@@ -112,13 +114,13 @@
  */
 CREATE TABLE xml_documents (
 	docid		VARCHAR(250),	-- the document id #
-	rootnodeid	INT8,	-- reference to root node of the DOM
+	rootnodeid	INT8,		-- reference to root node of the DOM
 	docname		VARCHAR(100),	-- usually the root element name
 	doctype		VARCHAR(100),	-- public id indicating document type
 	user_owner	VARCHAR(100),	-- the user owned the document
 	user_updated	VARCHAR(100),	-- the user updated the document
 	server_location INT8,	-- the server on which this document resides
-	rev 		INT8,   --the revision number of the document
+	rev 		INT8,   -- the revision number of the document
 	date_created	DATE,
 	date_updated	DATE,
 	public_access	INT8,	-- flag for public access
@@ -143,9 +145,10 @@
  */
 CREATE SEQUENCE xml_revisions_id_seq;
 CREATE TABLE xml_revisions (
-	revisionid	INT8  default nextval('xml_revisions_id_seq'), -- the revision number we are saving
+	revisionid	INT8  default nextval('xml_revisions_id_seq'),
+                                        -- the revision number we are saving
 	docid		VARCHAR(250),	-- the document id #
-	rootnodeid	INT8,	-- reference to root node of the DOM
+	rootnodeid	INT8,		-- reference to root node of the DOM
 	docname		VARCHAR(100),	-- usually the root element name
 	doctype		VARCHAR(100),	-- public id indicating document type
 	user_owner	VARCHAR(100),
@@ -209,9 +212,10 @@
 
 CREATE SEQUENCE xml_relation_id_seq;
 CREATE TABLE xml_relation (
-	relationid    INT8 default nextval('xml_relation_id_seq')  PRIMARY KEY, -- unique id
+	relationid    INT8 default nextval('xml_relation_id_seq') PRIMARY KEY,
+					     -- unique id
 	docid         VARCHAR(250) ,         -- the docid of the package file
-	                                      -- that this relation came from
+	                                     -- that this relation came from
         packagetype   VARCHAR(250),          -- the type of the package
 	subject       VARCHAR(512) NOT NULL, -- the subject of the relation
 	subdoctype    VARCHAR(128),         	-- the doctype of the subject
@@ -223,4 +227,15 @@
 		FOREIGN KEY (docid) REFERENCES xml_documents
   );
 
+/* 
+ * Table used as Unique ID generator for the uniqueid part of Accession#
+ */
+CREATE SEQUENCE accession_number_id_seq;
+CREATE TABLE accession_number (
+   uniqueid	INT8    default nextval('accession_number_id_seq') PRIMARY KEY,
+   site_code	VARCHAR(100),
+   date_created	DATE,
+);
 
+
+
Index: src/xmltables.sql
===================================================================
--- src/xmltables.sql	(revision 758)
+++ src/xmltables.sql	(revision 759)
@@ -25,11 +25,15 @@
 DROP SEQUENCE xml_replication_id_seq;
 DROP SEQUENCE accnum_uniqueid_seq;
 DROP SEQUENCE xml_documents_id_seq;
-
+DROP SEQUENCE accession_number_id_seq;
+               
+/* Drop triggers are not necessary */
+DROP TRIGGER xml_nodes_before_insert;
 DROP TRIGGER xml_revisions_before_insert;
 DROP TRIGGER xml_catalog_before_insert;
 DROP TRIGGER xml_relation_before_insert;
 DROP TRIGGER xml_replication_before_insert;
+DROP TRIGGER accession_number_before_insert;
 
 DROP TABLE xml_index;
 DROP TABLE xml_access;
@@ -39,6 +43,7 @@
 DROP TABLE xml_nodes;
 DROP TABLE xml_replication;
 DROP TABLE xml_catalog;
+DROP TABLE accession_number;
 
 /*
  *Replication -- table to store servers that metacat is replicated to
@@ -66,6 +71,7 @@
 /* 
  * Nodes -- table to store XML Nodes (both elements and attributes)
  */
+CREATE SEQUENCE xml_nodes_id_seq;
 CREATE TABLE xml_nodes (
 	nodeid		NUMBER(20),	-- the unique node id (pk)
 	nodeindex	NUMBER(10),	-- order of nodes within parent
@@ -85,16 +91,22 @@
    CONSTRAINT xml_nodes_parent_fk 
 		FOREIGN KEY (parentnodeid) REFERENCES xml_nodes
 );
-
+CREATE TRIGGER xml_nodes_before_insert
+BEFORE INSERT ON xml_nodes FOR EACH ROW
+BEGIN
+  SELECT xml_nodes_id_seq.nextval
+    INTO :new.nodeid
+    FROM dual;     
+END;    
+/
+                               
 /* 
- * Indexes of rootnodeid & parentnodeid in xml_nodes
+ * Indexes of rootnodeid, parentnodeid, and nodename in xml_nodes
  */
 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;
-
 /* 
  * XML Catalog -- table to store all external sources for XML documents
  */
@@ -148,11 +160,6 @@
 );
 
 /* 
- * Sequence to get uniqueID for Accession #
- */
-CREATE SEQUENCE xml_documents_id_seq;
-
-/* 
  * Index of <docid,doctype> in xml_document
  */
 CREATE INDEX xml_documents_idx1 ON xml_documents (docid, doctype);
@@ -258,6 +265,24 @@
   SELECT xml_relation_id_seq.nextval
     INTO :new.relationid
     FROM dual;
-END;
+END;                                   
 /
 
+/* 
+ * Table used as Unique ID generator for the uniqueid part of Accession#
+ */
+CREATE SEQUENCE accession_number_id_seq;
+CREATE TABLE accession_number (
+	uniqueid	NUMBER(20) PRIMARY KEY,
+	site_code	VARCHAR2(100),
+	date_created	DATE
+);
+CREATE TRIGGER accession_number_before_insert
+BEFORE INSERT ON accession_number FOR EACH ROW
+BEGIN
+  SELECT accession_number_id_seq.nextval
+    INTO :new.uniqueid
+    FROM dual;
+END;                                   
+/
+
Index: src/xmltables-sqlserver.sql
===================================================================
--- src/xmltables-sqlserver.sql	(revision 758)
+++ src/xmltables-sqlserver.sql	(revision 759)
@@ -17,128 +17,16 @@
 /*
  * Drop all of the objects in proper order
  */
-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
+drop table [dbo].[xml_index];
+drop table [dbo].[xml_access];
+drop table [dbo].[xml_revisions];
+drop table [dbo].[xml_relation];
+drop table [dbo].[xml_documents];
+drop table [dbo].[xml_nodes];
+drop table [dbo].[xml_replication];
+drop table [dbo].[xml_catalog];
+drop table [dbo].[accession_number];
 
-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
-
-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
-
-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
-
-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
-
 /* 
  * ACL -- table to store ACL for XML documents by principals
  */
@@ -262,6 +150,17 @@
   [public_access] [bit] NULL ,
   [catalog_id] [bigint] NULL 
 ) ON [PRIMARY]
+GO                                
+
+/* 
+ * Table used as Unique ID generator for the uniqueid part of Accession#
+ */
+CREATE TABLE [dbo].[accession_number] (
+  [uniqueid] [int] IDENTITY (1, 1) NOT NULL,
+  [site_code] [varchar] (100),
+  [date_created] [datetime],
+  CONSTRAINT [PK_accession_number] PRIMARY KEY CLUSTERED ([uniqueid])
+) ON [PRIMARY]
 GO
 
 /* 
