IF NOT EXISTS (SELECT 1 FROM sys.tables WHERE name = 'pxp_ccda_requests_locks')
CREATE TABLE pxp_ccda_requests_locks(
	id UNIQUEIDENTIFIER NOT NULL,
	request_id UNIQUEIDENTIFIER NOT NULL,
	consumer_id INT NOT NULL,
	ccda_type TINYINT NOT NULL,
	is_acquired BIT NOT NULL DEFAULT(1),
	unix_milliseconds BIGINT NOT NULL,
	is_released BIT NOT NULL DEFAULT(0),	
	created_by INT NOT NULL,
	create_timestamp DATETIME NOT NULL DEFAULT GETDATE(),
	modified_by INT NOT NULL,
	modify_timestamp DATETIME NOT NULL DEFAULT GETDATE(),
	row_timestamp TIMESTAMP NOT NULL
)ON NEXTGEN_CORE;
GO

EXECUTE NG_INDEX_MAINT
@PI_TABLE_NAME = 'pxp_ccda_requests_locks',
@PI_INDEX_NAME = 'PK_pxp_ccda_requests_locks',
@PI_INDEX_COLUMNS = 'id',
@PI_INCLUDED_COLUMNS = NULL,
@PI_PRIMARY_IND = 'Y',
@PI_CLUSTERED_IND = 'N',
@PI_UNIQUE_IND = 'Y',
@PI_NG_SYSTEM_IND = 'Y',
@PI_FULLTEXT_IND = 'N',
@PI_FILL_FACTOR = 90,
@PI_PRINT_IND = 'N',
@PI_DROP_INDEX = 'N'
GO

IF NOT EXISTS (SELECT 1 FROM sys.tables WHERE name = 'pxp_ccda_requests_locks_archive')
CREATE TABLE pxp_ccda_requests_locks_archive(
	id 	UNIQUEIDENTIFIER NOT NULL,
	request_id 	UNIQUEIDENTIFIER NOT NULL,	
	ccda_type 	TINYINT NOT NULL,
	is_completed 	BIT NOT NULL,
	created_by 	INT NOT NULL,
	create_timestamp 	DATETIME NOT NULL DEFAULT GETDATE(),
	modified_by 	INT NOT NULL,
	modify_timestamp	DATETIME NOT NULL DEFAULT GETDATE(),
	row_timestamp 	TIMESTAMP NOT NULL
)ON NEXTGEN_CORE;
GO

EXECUTE NG_INDEX_MAINT
@PI_TABLE_NAME = 'pxp_ccda_requests_locks_archive',
@PI_INDEX_NAME = 'PK_pxp_ccda_requests_locks_archive',
@PI_INDEX_COLUMNS = 'id',
@PI_INCLUDED_COLUMNS = NULL,
@PI_PRIMARY_IND = 'Y',
@PI_CLUSTERED_IND = 'N',
@PI_UNIQUE_IND = 'Y',
@PI_NG_SYSTEM_IND = 'Y',
@PI_FULLTEXT_IND = 'N',
@PI_FILL_FACTOR = 90,
@PI_PRINT_IND = 'N',
@PI_DROP_INDEX = 'N'
GO




