UPDATE TBIDB_BASE SET CONFIG_VALUE = '1.1.3' where CONFIG_NAME = 'DB_VERSION'
GO

CREATE PROCEDURE [dbo].[PRIDB_DELETE_IDB_OBJECT_FINALLY] @pIDB_OBJ_ID BIGINT 
AS
							
BEGIN
		DELETE FROM TBIDB_CONVERSATION_MESSAGE WHERE CONV_ID IN (SELECT GUID FROM TBIDB_CONVERSATION_OBJECT WHERE IDB_OBJ_ID = @pIDB_OBJ_ID);
		DELETE FROM TBIDB_CONVERSATION_USER WHERE CONV_ID IN (SELECT GUID FROM TBIDB_CONVERSATION_OBJECT WHERE IDB_OBJ_ID = @pIDB_OBJ_ID);
		DELETE FROM TBIDB_CONVERSATION_OBJECT WHERE IDB_OBJ_ID = @pIDB_OBJ_ID;
		DELETE FROM TBIDB_ACCESSRIGHT WHERE IDB_OBJ_ID = @pIDB_OBJ_ID;
		DELETE FROM TBIDB_OBJECT_STRUCTURE_TYPE WHERE IDB_OBJ_ID = @pIDB_OBJ_ID;
		DELETE FROM TBIDB_LANGUAGE_TERM WHERE OBJECT_ID in (SELECT GUID FROM TBIDB_OBJECT_METADATA WHERE IDB_OBJ_ID = @pIDB_OBJ_ID )
		DELETE FROM TBIDB_OBJECT_METADATA WHERE IDB_OBJ_ID = @pIDB_OBJ_ID;
		DELETE FROM TBIDB_OBJECT_METADATA_DELETE WHERE IDB_OBJ_ID = @pIDB_OBJ_ID;
		DELETE FROM TBIDB_OBJECT_METADATA_CHANGE WHERE IDB_OBJ_ID = @pIDB_OBJ_ID;
		DELETE FROM TBIDB_OBJECT_METADATA_ADD WHERE IDB_OBJ_ID = @pIDB_OBJ_ID;
		DELETE FROM TBIDB_OBJECT_BE WHERE IDB_OBJ_ID = @pIDB_OBJ_ID;
		DELETE FROM TBIDB_DOC_INFO WHERE IDB_OBJ_ID = @pIDB_OBJ_ID;
		DELETE FROM TBIDB_FILE_OBJECT WHERE IDB_OBJ_ID = @pIDB_OBJ_ID;
		DELETE FROM TBIDB_OBJECT_STRUCTURE_TYPE WHERE IDB_OBJ_ID = @pIDB_OBJ_ID;
		DELETE FROM TBIDB_OBJECT WHERE IDB_OBJ_ID = @pIDB_OBJ_ID;
	END

GO
