-- Definition of the tables residing in the DEFINITION_SCHEMA.
-- These are tables that cannot be referenced directly, but only
-- via the views defined in the INFORMATION_SCHEMA.

CREATE TABLE CLUSTERS(
   CLUSTER_PK		PRIMARY_KEY,	-- 0
   "CLUSTER_NAME"	VARCHAR(256)	-- 1
);


CREATE TABLE CATALOGS(
   CATALOG_PK		PRIMARY_KEY,	-- 0
   "CATALOG_NAME"	VARCHAR(256),	-- 1
   CLUSTER_PK		PRIMARY_KEY	-- 2
);


CREATE TABLE USERS(
   USER_PK		PRIMARY_KEY,	-- 0
   USER_NAME		VARCHAR(256),	-- 1
   PASSWORD		VARCHAR(256),	-- 2
   DEFAULT_SCHEMA	PRIMARY_KEY,	-- 3
   DEFAULT_GROUP	PRIMARY_KEY,	-- 4
	INDEX(USER_NAME),
	INDEX(USER_PK)
);


CREATE TABLE SCHEMATA(
   SCHEMA_PK		PRIMARY_KEY,	-- 0
   SCHEMA_OWNER_PK	PRIMARY_KEY,	-- 1
   CATALOG_PK		PRIMARY_KEY,	-- 2
   "SCHEMA_NAME"	VARCHAR(256),   -- 3
   CHARACTER_SET_PK	PRIMARY_KEY,	-- 4
   SCHEMA_PERMISSIONS	INTEGER,	-- 5
	INDEX(CATALOG_PK, "SCHEMA_NAME")
);


CREATE TABLE TABLES(
   TABLE_PK			PRIMARY_KEY,	-- 0
   CATALOG_PK			PRIMARY_KEY,	-- 1
   SCHEMA_PK			PRIMARY_KEY,	-- 2
   "TABLE_NAME"			VARCHAR(256),	-- 3
   TABLE_TYPE			VARCHAR(16),	-- 4
   COLUMN_COUNT			INTEGER,	-- 5
   DEFAULT_INDEX_MODE		INTEGER,	-- 6
   DATA_TABLE_PK		PRIMARY_KEY,	-- 7
   ON_COMMIT_ACTION		INTEGER,	-- 8
   PSEUDO_TABLE_KIND		VARCHAR(3),	-- 9, "SPH" | "LKS" | "LSW"
   HAS_DOMAIN_CONSTRAINTS	VARCHAR(3),	-- 10
	INDEX(SCHEMA_PK, "TABLE_NAME"),
	INDEX(DATA_TABLE_PK),
   INDEX("TABLE_NAME"),
   INDEX(TABLE_PK)
);


CREATE TABLE DATA_TYPE_DESCRIPTOR(
   DATA_TYPE_DESCRIPTOR_PK	PRIMARY_KEY,	-- 0
   TABLE_OR_DOMAIN_PK		PRIMARY_KEY,	-- 1
   COLUMN_NAME_PK		PRIMARY_KEY,	-- 2
   DATA_TYPE			VARCHAR(40),	-- 3
   DATA_TYPE_CODE		INTEGER,	-- 4
   CHARACTER_MAXIMUM_LENGTH	INTEGER,	-- 5
   CHARACTER_OCTET_LENGTH	INTEGER,	-- 6
   CHARACTER_SET_PK		PRIMARY_KEY,	-- 7
   COLLATION_PK			PRIMARY_KEY,	-- 8
   NUMERIC_PRECISION		INTEGER,	-- 9
   NUMERIC_PRECISION_RADIX	INTEGER,	-- 10
   NUMERIC_SCALE		INTEGER,	-- 11
   DATETIME_PRECISION		INTEGER,	-- 12
   INTERVAL_FROM		INTEGER,	-- 13
   INTERVAL_TO			INTEGER,	-- 14
   DATETIME_PRECISION_LEADING	INTEGER,	-- 15
	INDEX(TABLE_OR_DOMAIN_PK, COLUMN_NAME_PK),
	INDEX(COLUMN_NAME_PK)
);


CREATE TABLE DOMAINS(
   DOMAIN_PK		PRIMARY_KEY,		-- 0
   CATALOG_PK		PRIMARY_KEY,		-- 1
   SCHEMA_PK		PRIMARY_KEY,		-- 2
   DOMAIN_NAME		VARCHAR(256),		-- 3
   DOMAIN_DEFAULT_IL1	VARCHAR(1000000),	-- 4
   IS_NULLABLE		VARCHAR(3),		-- 5
   DOMAIN_PERMISSIONS	INTEGER,		-- 6
   COLLATION_PK		PRIMARY_KEY,		-- 7
   DOMAIN_DEFAULT	VARCHAR(1000000),	-- 8
	INDEX(SCHEMA_PK, DOMAIN_NAME)
);


CREATE TABLE DOMAIN_CONSTRAINTS(
   DOMAIN_CONSTRAINT_PK	PRIMARY_KEY,		-- 0
   CATALOG_PK		PRIMARY_KEY,		-- 1
   SCHEMA_PK		PRIMARY_KEY,		-- 2
   CONSTRAINT_NAME_PK	PRIMARY_KEY,		-- 3
   DOMAIN_PK		PRIMARY_KEY,		-- 4
   IS_DEFERRABLE	VARCHAR(3),		-- 5
   INITIALLY_DEFERRED   VARCHAR(3),		-- 6
	INDEX(CONSTRAINT_NAME_PK),
	INDEX(DOMAIN_PK)
);


CREATE TABLE VIEWS(
   VIEW_PK		PRIMARY_KEY,		-- 0
   TABLE_PK		PRIMARY_KEY,		-- 1
   VIEW_DEFINITION_IL1	VARCHAR(1000000),	-- 2
   CHECK_OPTION		VARCHAR(8),		-- 3
   IS_UPDATABLE		VARCHAR(3),		-- 4
   VIEW_DEFINITION	VARCHAR(1000000),	-- 5
	INDEX(TABLE_PK)
);


CREATE TABLE COLUMNS(
   COLUMN_PK		PRIMARY_KEY,		-- 0
   ORDINAL_POSITION	PRIMARY_KEY,		-- 1
   TABLE_PK		PRIMARY_KEY,		-- 2
   "COLUMN_NAME"	VARCHAR(256),		-- 3
   DOMAIN_PK		PRIMARY_KEY,		-- 4
   COLUMN_DEFAULT_IL1	VARCHAR(1000000),	-- 5
   IS_NULLABLE		VARCHAR(3),		-- 6
   COLUMN_PERMISSIONS	INTEGER,		-- 7
   COLUMN_DEFAULT	VARCHAR(1000000),	-- 8
	INDEX(TABLE_PK, "COLUMN_NAME"),
	INDEX(DOMAIN_PK)
);


CREATE TABLE VIEW_TABLE_USAGE(
   VIEW_TABLE_USAGE_PK	PRIMARY_KEY,	-- 0
   VIEW_PK		PRIMARY_KEY,	-- 1
   TABLE_PK		PRIMARY_KEY,	-- 2
	INDEX(TABLE_PK)
);


CREATE TABLE VIEW_COLUMN_USAGE(
   VIEW_COLUMN_USAGE_PK	PRIMARY_KEY,	-- 0
   VIEW_PK		PRIMARY_KEY,	-- 1
   TABLE_PK		PRIMARY_KEY,	-- 2
   COLUMN_PK		PRIMARY_KEY,	-- 3
	INDEX(COLUMN_PK)
);


CREATE TABLE VIEW_OBJECT_USAGE(
   VIEW_COLUMN_USAGE_PK	PRIMARY_KEY,	-- 0
   VIEW_PK		PRIMARY_KEY,	-- 1
   OBJECT_TYPE		VARCHAR(13),	-- 2
   OBJECT_PK		PRIMARY_KEY,	-- 3
	INDEX(OBJECT_PK, OBJECT_TYPE)
);


CREATE TABLE CONSTRAINT_NAMES(
   CONSTRAINT_NAMES_PK	PRIMARY_KEY,	-- 0
   CATALOG_PK		PRIMARY_KEY,	-- 1
   SCHEMA_PK		PRIMARY_KEY,	-- 2
   "CONSTRAINT_NAME"	VARCHAR(256),	-- 3
   CONSTRAINT_KIND	VARCHAR(9),	-- 4
	INDEX(SCHEMA_PK, "CONSTRAINT_NAME"),
        INDEX(CONSTRAINT_NAMES_PK)
);


CREATE TABLE TABLE_CONSTRAINTS(
   TABLE_CONSTRAINTS_PK	PRIMARY_KEY,	-- 0
   CATALOG_PK		PRIMARY_KEY,	-- 1
   SCHEMA_PK		PRIMARY_KEY,	-- 2
   CONSTRAINT_NAME_PK	PRIMARY_KEY,	-- 3
   CONSTRAINT_TYPE	VARCHAR(11),	-- 4
   TABLE_PK		PRIMARY_KEY,	-- 5
   IS_DEFERRABLE	VARCHAR(3),	-- 6
   INITIALLY_DEFERRED	VARCHAR(3),	-- 7
	INDEX(CONSTRAINT_NAME_PK),
	INDEX(TABLE_PK, CONSTRAINT_TYPE)
);


CREATE TABLE KEY_COLUMN_USAGE(
   KEY_COLUMN_USAGE_PK	PRIMARY_KEY,	-- 0
   CONSTRAINT_NAME_PK	PRIMARY_KEY,	-- 1
   TABLE_PK		PRIMARY_KEY,	-- 2
   COLUMN_PK		PRIMARY_KEY,	-- 3
   ORDINAL_POSITION	INTEGER,	-- 4
	INDEX(CONSTRAINT_NAME_PK, TABLE_PK),
	INDEX(COLUMN_PK)
);


CREATE TABLE REFERENTIAL_CONSTRAINTS(
   REFERENTIAL_CONSTRAINTS_PK	PRIMARY_KEY,	-- 0
   CONSTRAINT_NAME_PK		PRIMARY_KEY,	-- 1
   UNIQUE_CONSTRAINT_NAME_PK	PRIMARY_KEY,	-- 2
   MATCH_OPTION			VARCHAR(7),	-- 3
   UPDATE_RULE			VARCHAR(11),	-- 4
   DELETE_RULE			VARCHAR(11),	-- 5
	INDEX(CONSTRAINT_NAME_PK),
	INDEX(UNIQUE_CONSTRAINT_NAME_PK)
);


CREATE TABLE CHECK_CONSTRAINTS(
   CHECK_CONSTRAINTS_PK	PRIMARY_KEY,		-- 0
   CONSTRAINT_NAME_PK	PRIMARY_KEY,		-- 1
   CHECK_CLAUSE_IL1	VARCHAR(1000000),	-- 2
   CHECK_CLAUSE		VARCHAR(1000000),	-- 3
	INDEX(CONSTRAINT_NAME_PK),
);


CREATE TABLE CHECK_TABLE_USAGE(
   CHECK_TABLE_USAGE_PK	PRIMARY_KEY,		-- 0
   CONSTRAINT_NAME_PK	PRIMARY_KEY,		-- 1
   TABLE_PK		PRIMARY_KEY,		-- 2
	INDEX(TABLE_PK)
);


CREATE TABLE CHECK_COLUMN_USAGE(
   CHECK_COLUMN_USAGE_PK	PRIMARY_KEY,	-- 0
   CONSTRAINT_NAME_PK		PRIMARY_KEY,	-- 1
   TABLE_PK			PRIMARY_KEY,	-- 2
   COLUMN_PK			PRIMARY_KEY,	-- 3
	INDEX(COLUMN_PK)
);


CREATE TABLE CHECK_OBJECT_USAGE(
   CHECK_COLUMN_USAGE_PK	PRIMARY_KEY,	-- 0
   CONSTRAINT_NAME_PK		PRIMARY_KEY,	-- 1
   OBJECT_TYPE			VARCHAR(13),	-- 2
   OBJECT_PK			PRIMARY_KEY,	-- 3
	INDEX(OBJECT_PK, OBJECT_TYPE)
);


CREATE TABLE ASSERTIONS(
   ASSERTIONS_PK	PRIMARY_KEY,	-- 0
   CATALOG_PK		PRIMARY_KEY,	-- 1
   SCHEMA_PK		PRIMARY_KEY,	-- 2
   CONSTRAINT_NAME_PK	PRIMARY_KEY,	-- 3
   IS_DEFERRABLE	VARCHAR(3),	-- 4
   INITIALLY_DEFERRED	VARCHAR(3),	-- 5
	INDEX(SCHEMA_PK, CONSTRAINT_NAME_PK),
	INDEX(CONSTRAINT_NAME_PK)
);


CREATE TABLE TABLE_PRIVILEGES(
   TABLE_PRIVILEGES_PK	PRIMARY_KEY,	-- 0
   GRANTOR_PK		PRIMARY_KEY,	-- 1
   GRANTEE_PK		PRIMARY_KEY,	-- 2
   CATALOG_PK		PRIMARY_KEY,	-- 3
   SCHEMA_PK		PRIMARY_KEY,	-- 4
   TABLE_PK		PRIMARY_KEY,	-- 5
   PRIVILEGE_TYPE	VARCHAR(10),	-- 6
   IS_GRANTABLE		VARCHAR(3),	-- 7
	INDEX(GRANTEE_PK, TABLE_PK, PRIVILEGE_TYPE, GRANTOR_PK),
	INDEX(SCHEMA_PK, GRANTOR_PK, TABLE_PK)
);


CREATE TABLE COLUMN_PRIVILEGES(
   COLUMN_PRIVILEGES_PK	PRIMARY_KEY,	-- 0
   GRANTOR_PK		PRIMARY_KEY,	-- 1
   GRANTEE_PK		PRIMARY_KEY,	-- 2
   CATALOG_PK		PRIMARY_KEY,	-- 3,
   SCHEMA_PK		PRIMARY_KEY,	-- 4,
   TABLE_PK		PRIMARY_KEY,	-- 5
   COLUMN_PK		PRIMARY_KEY,	-- 6
   PRIVILEGE_TYPE	VARCHAR(10),	-- 7
   IS_GRANTABLE		VARCHAR(3),	-- 8
	INDEX(GRANTEE_PK, COLUMN_PK, PRIVILEGE_TYPE, GRANTOR_PK),
	   -- Since COLUMN_PKs are unique within the whole database,
	   -- we don't need to include the TABLE_PK in the index.
        INDEX(GRANTEE_PK, TABLE_PK, PRIVILEGE_TYPE),
	INDEX(SCHEMA_PK, GRANTOR_PK, TABLE_PK)
);


CREATE TABLE USAGE_PRIVILEGES(
   USAGE_PRIVILEGES_PK	PRIMARY_KEY,	-- 0
   GRANTOR_PK		PRIMARY_KEY,	-- 1
   GRANTEE_PK		PRIMARY_KEY,	-- 2
   CATALOG_PK		PRIMARY_KEY,	-- 3,
   SCHEMA_PK		PRIMARY_KEY,	-- 4,
   OBJECT_PK		PRIMARY_KEY,	-- 5
   OBJECT_TYPE		VARCHAR(13),	-- 6
   IS_GRANTABLE		VARCHAR(3),	-- 7
	INDEX(GRANTEE_PK, OBJECT_PK, OBJECT_TYPE, GRANTOR_PK),
        INDEX(SCHEMA_PK, GRANTOR_PK, OBJECT_PK)
);


CREATE TABLE CHARACTER_SETS(
   CHARACTER_SETS_PK	PRIMARY_KEY,	-- 0
   CATALOG_PK		PRIMARY_KEY,	-- 1
   SCHEMA_PK		PRIMARY_KEY,	-- 2
   "CHARACTER_SET_NAME"	VARCHAR(256),	-- 3
   FORM_OF_USE		VARCHAR(256),	-- 4
   NUMBER_OF_CHARACTERS	INTEGER,	-- 5
   DEFAULT_COLLATE_PK	PRIMARY_KEY,	-- 6
	INDEX(SCHEMA_PK, "CHARACTER_SET_NAME")
);


CREATE TABLE COLLATIONS(
   COLLATIONS_PK	PRIMARY_KEY,	-- 0
   CATALOG_PK		PRIMARY_KEY,	-- 1
   SCHEMA_PK		PRIMARY_KEY,	-- 2
   "COLLATION_NAME"	VARCHAR(256),	-- 3
   CHARACTER_SET_PK	PRIMARY_KEY,	-- 4
   PAD_ATTRIBUTE	VARCHAR(9),	-- 5
   COLLATION_TYPE       VARCHAR(11),	-- 6, ORDINAL, EXTERNAL, TRANSLATION,
					--    REVERSE, INHERITED
   EXTERNAL_NAME        VARCHAR(1024),	-- 7
   TRANSLATION_PK	PRIMARY_KEY,	-- 8
   COLLATION_PK		PRIMARY_KEY,	-- 9
	INDEX(SCHEMA_PK, "COLLATION_NAME")
);


CREATE TABLE TRANSLATIONS(
   TRANSLATIONS_PK		PRIMARY_KEY,	-- 0
   CATALOG_PK			PRIMARY_KEY,	-- 1
   SCHEMA_PK			PRIMARY_KEY,	-- 2
   TRANSLATION_NAME		VARCHAR(256),	-- 3
   SOURCE_CHARACTER_SET_PK	PRIMARY_KEY,	-- 4
   TARGET_CHARACTER_SET_PK	PRIMARY_KEY,	-- 5
   TRANSLATION_TYPE		VARCHAR(11),	-- 6, EXTERNAL, IDENTITY,
						--    INHERITED
   EXTERNAL_NAME        	VARCHAR(1024),	-- 7
   TRANSLATION_PK		PRIMARY_KEY,	-- 8
	INDEX(SCHEMA_PK, "TRANSLATION_NAME")
);


CREATE TABLE SQL_LANGUAGES(
   SQL_LANGUAGES_PK			PRIMARY_KEY,	-- 0
   SQL_LANGUAGE_SOURCE			VARCHAR(8),	-- 1
   SQL_LANGUAGE_YEAR			VARCHAR(4),	-- 2
   SQL_LANGUAGE_CONFORMANCE		VARCHAR(12),	-- 3
   SQL_LANGUAGE_INTEGRITY		VARCHAR(3),	-- 4
   SQL_LANGUAGE_IMPLEMENTATION		VARCHAR(3),	-- 5
   SQL_LANGUAGE_BINDING_STYLE		VARCHAR(8),	-- 6
   SQL_LANGUAGE_PROGRAMMING_LANGUAGE	VARCHAR(7)	-- 7
);


CREATE TABLE INDEXES(
   INDEXES_PK			PRIMARY_KEY,	-- 0
   CATALOG_PK			PRIMARY_KEY,	-- 1
   SCHEMA_PK			PRIMARY_KEY,	-- 2
   INDEX_NAME			VARCHAR(256),	-- 3
   TABLE_PK			PRIMARY_KEY,	-- 4
   INDEX_COLUMN_COUNT		INTEGER,	-- 5
   INDEX_COLUMNS		VARCHAR(2048),	-- 6
   CONSTRAINT_NAME_PK		PRIMARY_KEY,	-- 7
   INDEX_TYPE			INTEGER,	-- 8
   REFD_TABLE_PK		INTEGER,	-- 9, valid iff INDEX_TYPE == foreign key index
	INDEX(SCHEMA_PK, INDEX_NAME),
	INDEX(TABLE_PK, CONSTRAINT_NAME_PK),
	INDEX(SCHEMA_PK),
	INDEX(INDEXES_PK)
);


CREATE TABLE INDEX_COLUMN_USAGE(
   INDEX_COLUMN_USAGE_PK	PRIMARY_KEY,	-- 0
   INDEX_PK			PRIMARY_KEY,	-- 1
   TABLE_PK			PRIMARY_KEY,	-- 2
   COLUMN_PK			PRIMARY_KEY,	-- 3
   ORDINAL_POSITION		INTEGER,	-- 4
	INDEX(COLUMN_PK),
	INDEX(INDEX_PK, TABLE_PK)
);


CREATE TABLE TEMP_TABLES(
   TEMP_TABLES_PK		PRIMARY_KEY,	-- 0
   SCHEMA_PK			PRIMARY_KEY,	-- 1, Fake schema name
   TABLES_PK			PRIMARY_KEY,	-- 2, TABLES entry
   DATA_TABLE_PK		PRIMARY_KEY,	-- 3, The data bearing table
   TABLE_TYPE			INTEGER,        -- 4  Declared|Local|Global
	INDEX(SCHEMA_PK, TABLES_PK)
);


CREATE TABLE TABLE_CACHE_SETTINGS(
   TABLE_CACHE_SETTING_PK	PRIMARY_KEY,	-- 0
   CATALOG_PK			PRIMARY_KEY,	-- 1,
   SCHEMA_PK			PRIMARY_KEY,	-- 2,
   TABLES_PK			PRIMARY_KEY,	-- 3,
   LOWER_LIMIT			INTEGER,	-- 4,
   UPPER_LIMIT			INTEGER,	-- 5,
   PERCENT			INTEGER,	-- 6,
   PERSISTENT			VARCHAR(3),	-- 7,
   PRELOAD			VARCHAR(3), 	-- 8
	INDEX(SCHEMA_PK, TABLES_PK)
);


--CREATE TABLE WHISKEY_LIST(
--   WHISKEY_LIST_PK	PRIMARY_KEY,	-- 0
--   IP_ADDR		CHAR(256),	-- 1
--   NETMASK		CHAR(256),	-- 2
--   WHITE_LISTED	CHAR(3),	-- 3
--   SECURE		CHAR(3),	-- 4
--	INDEX(WHISKEY_LIST_PK)
--);


CREATE TABLE GROUPS(
   GROUP_PK	PRIMARY_KEY,	-- 0
   GROUP_NAME   VARCHAR(256),	-- 1
	INDEX(GROUP_PK),
	INDEX(GROUP_NAME)
);


CREATE TABLE GROUP_USER_USAGE(
   GROUP_PK	PRIMARY_KEY,	-- 0
   USER_PK	PRIMARY_KEY,	-- 1
	INDEX(GROUP_PK, USER_PK),
	INDEX(USER_PK)
);


CREATE TABLE ROW_PRIVILEGE_DEFAULTS(
   USER_PK		PRIMARY_KEY,	-- 0
   TABLE_PK		PRIMARY_KEY,	-- 1
   PRIVILEGE_MASK	INTEGER,	-- 2
	INDEX(USER_PK, TABLE_PK)
);


CREATE TABLE PSM_ROUTINES(
   PSM_DEFINITION_PK	PRIMARY_KEY,		-- 0
   CATALOG_PK		PRIMARY_KEY,		-- 1
   SCHEMA_PK		PRIMARY_KEY,		-- 2
   SPECIFIC_NAME	VARCHAR(256),		-- 3
   ROUTINE_NAME		VARCHAR(256),		-- 4
   PARAMETER_COUNT	INTEGER,		-- 5
   SQL_STMT		VARCHAR(1000000),	-- 6
   SQL_STMT_IL1		VARCHAR(1000000),	-- 7
   ROUTINE_KIND		VARCHAR(9),		-- 8
   RETURN_TYPE_PK	PRIMARY_KEY,		-- 9
	INDEX(SCHEMA_PK, SPECIFIC_NAME),
	INDEX(SCHEMA_PK, ROUTINE_NAME, ROUTINE_KIND)
);


CREATE TABLE PSM_PARAMETERS(
   PSM_PARAMETERS_PK	PRIMARY_KEY,	-- 0
   PSM_ROUTINE_PK	PRIMARY_KEY,	-- 1
   MODE			VARCHAR(5),	-- 2
   PARAMETER_NAME	VARCHAR(256),	-- 3
   DATATYPE_PK		PRIMARY_KEY,	-- 4
   ORDINAL_POSITION	INTEGER,	-- 5
	INDEX(PSM_ROUTINE_PK)
);


CREATE TABLE PSM_USAGE(
   PSM_USAGE_PK			PRIMARY_KEY,	-- 0
   REFERENCING_ROUTINE_PK	PRIMARY_KEY,	-- 1
   REFERENCED_ROUTINE_PK	PRIMARY_KEY	-- 2
	INDEX(REFERENCED_ROUTINE_PK),
	INDEX(REFERENCING_ROUTINE_PK)
);


CREATE TABLE PSM_DEFAULT_USAGE(
   PSM_DEFAULT_USAGE_PK		PRIMARY_KEY,	-- 0
   REFERENCED_ROUTINE_PK	PRIMARY_KEY,	-- 1
   DOMAIN_PK			PRIMARY_KEY,	-- 2
   COLUMN_PK			PRIMARY_KEY,	-- 3
	INDEX(REFERENCED_ROUTINE_PK),
	INDEX(DOMAIN_PK),
	INDEX(COLUMN_PK)
);


CREATE TABLE PSM_CHECK_USAGE(
   PSM_USAGE_PK			PRIMARY_KEY,	-- 0
   REFERENCED_ROUTINE_PK	PRIMARY_KEY,	-- 1
   CHECK_CONSTRAINT_PK		PRIMARY_KEY	-- 2
	INDEX(REFERENCED_ROUTINE_PK),
	INDEX(CHECK_CONSTRAINT_PK)
);


CREATE TABLE EXECUTE_PRIVILEGES(
   EXECUTE_PRIVILEGES_PK	PRIMARY_KEY,	-- 0
   GRANTOR_PK			PRIMARY_KEY,	-- 1
   GRANTEE_PK			PRIMARY_KEY,	-- 2
   CATALOG_PK			PRIMARY_KEY,	-- 3,
   SCHEMA_PK			PRIMARY_KEY,	-- 4,
   ROUTINE_PK			PRIMARY_KEY,	-- 5
   IS_GRANTABLE			VARCHAR(3),	-- 6
	INDEX(GRANTEE_PK, ROUTINE_PK, GRANTOR_PK),
	INDEX(SCHEMA_PK, GRANTOR_PK, ROUTINE_PK)
);


-- See FBLookSeeRow.h
CREATE TABLE LS_INDEXES(
   LS_INDEXES_PK	PRIMARY_KEY,		-- 0
   CATALOG_PK		PRIMARY_KEY,		-- 1
   SCHEMA_PK		PRIMARY_KEY,		-- 2
   INDEX_NAME		VARCHAR(256),		-- 3
   TABLE_PK		PRIMARY_KEY,		-- 4
   INDEX_DESCRIPTOR	VARCHAR(1000000),	-- 5
   INDEX_ARGS		VARCHAR(1000000),       -- 6
   INDEX_HANDLE		INTEGER,		-- 7
   VERSION		INTEGER,                -- 8
   FLAGS		INTEGER,                -- 9
   COLLATION_PK		INTEGER,                -- 10
	INDEX(SCHEMA_PK, INDEX_NAME)
);


CREATE TABLE TRIGGERS(
   TRIGGERS_PK				PRIMARY_KEY,	-- 0
   TRIGGER_CATALOG_PK			PRIMARY_KEY,	-- 1
   TRIGGER_SCHEMA_PK			PRIMARY_KEY,	-- 2
   TRIGGER_NAME				VARCHAR(256),	-- 3
   EVENT_MANIPULATION			CHAR(6),	-- 4, "INSERT", "DELETE", "UPDATE"
   EVENT_OBJECT_TABLE_PK		PRIMARY_KEY,	-- 5
   ACTION_ORDER				INTEGER,	-- 6
   ACTION_CONDITION			VARCHAR(1000000),	-- 7
   ACTION_STATEMENT_LIST		VARCHAR(1000000),	-- 8
   TRIGGER_LEVEL			VARCHAR(9),	-- 9, "ROW", "STATEMENT"
   ACTION_TIME				VARCHAR(11),	-- 10, "BEFORE", "AFTER", "INSTEAD OF"
   CONDITION_REFERENCE_OLD_TABLE	VARCHAR(256),	-- 11
   CONDITION_REFERENCE_NEW_TABLE	VARCHAR(256),	-- 12
   CONDITION_REFERENCE_OLD_ROW		VARCHAR(256),	-- 13
   CONDITION_REFERENCE_NEW_ROW		VARCHAR(256),	-- 14
   COLUMN_LIST_IS_IMPLICIT		VARCHAR(3),	-- 15, "YES", "NO"

   ACTION_CONDITION_IL1			VARCHAR(1000000),	-- 16
   ACTION_STATEMENT_LIST_IL1		VARCHAR(1000000),	-- 17
	INDEX(TRIGGER_SCHEMA_PK, TRIGGER_NAME, EVENT_MANIPULATION),
	INDEX(EVENT_OBJECT_TABLE_PK)
);


CREATE TABLE TRIGGERED_UPDATE_COLUMNS(		-- Should (maybe) have been called TRIGGERED_COLUMNS
   TRIGGERED_UPDATE_COLUMNS_PK	PRIMARY_KEY,	-- 0
   TRIGGER_PK			PRIMARY_KEY,	-- 1
   EVENT_OBJECT_PK		PRIMARY_KEY,	-- 2
   EVENT_OBJECT_COLUMN_PK	PRIMARY_KEY,	-- 3
	INDEX(TRIGGER_PK),
	INDEX(EVENT_OBJECT_PK),
	INDEX(EVENT_OBJECT_COLUMN_PK)
);


CREATE TABLE TRIGGER_TABLE_USAGE(
   TRIGGER_TABLE_USAGE_PK	PRIMARY_KEY,	-- 0
   TRIGGER_PK			PRIMARY_KEY,	-- 1
   TABLE_PK			PRIMARY_KEY,	-- 2
	INDEX(TRIGGER_PK),
	INDEX(TABLE_PK)
);


CREATE TABLE TRIGGER_COLUMN_USAGE(
   TRIGGER_COLUMN_USAGE_PK	PRIMARY_KEY,	-- 0
   TRIGGER_PK			PRIMARY_KEY,	-- 1
   TABLE_PK			PRIMARY_KEY,	-- 2
   COLUMN_PK			PRIMARY_KEY,	-- 3
	INDEX(TRIGGER_PK),
	INDEX(TABLE_PK),
	INDEX(COLUMN_PK)
);


CREATE TABLE TRIGGER_OBJECT_USAGE(
   TRIGGER_OBJECT_USAGE_PK	PRIMARY_KEY,	-- 0
   TRIGGER_PK			PRIMARY_KEY,	-- 1
   OBJECT_TYPE			VARCHAR(13),	-- 2
   OBJECT_PK			PRIMARY_KEY,	-- 3
	INDEX(OBJECT_PK, OBJECT_TYPE),
         INDEX(TRIGGER_PK)
);
