USE DD_ECM

ALTER TABLE TBMT_TEMPLATE_ITEMS ADD PREFER_EXTERNAL bit NOT NULL DEFAULT (1)

ALTER VIEW [dbo].[VWMT_ITEMS]
AS
	SELECT DISTINCT
		[TBTEMPLATES].[NAME] [TEMPLATE_NAME]
		,[TBTABLES].[NAME] AS [XML_TABLE]
		,[TBITEMS].[XML_NAME] AS [XML_ITEM]		
		,[TBTYPES].[NAME] AS [DATA_TYPE]
		,[TBTABLES].[IS_HEAD] AS [IS_HEAD]
		,[TBITEMS].[IS_READ_ONLY]
		,[TBITEMS].[IS_VISIBLE]
        ,[TBITEMS].[IS_REQUIRED]
		,[TBITEMS].[IS_VIRTUAL]
		,[TBITEMS].[ORDER_KEY]
		,[TBITEMS].[PREFER_EXTERNAL]
		,[TBFUNCTIONS].[GUID] AS [FUNCTION_ID]
		,[TBFUNCTIONS].[NAME] AS [FUNCTION_NAME]
		,[TBITEMS].[FUNCTION_PARAMETERS]
	FROM
		[dbo].[TBMT_TEMPLATE_ITEMS] [TBITEMS]
		INNER JOIN [dbo].[TBMT_TABLES] [TBTABLES] ON [TBITEMS].[XML_TABLE_ID] = [TBTABLES].[GUID]
		INNER JOIN [dbo].[TBMT_TYPES] [TBTYPES] ON [TBITEMS].[XML_TYPE_ID] = [TBTYPES].[GUID]
		INNER JOIN [dbo].[TBMT_TEMPLATES] [TBTEMPLATES] ON [TBTABLES].[TEMPLATE_ID] = [TBTEMPLATES].[GUID]
		LEFT OUTER JOIN [dbo].[TBMT_FUNCTIONS] [TBFUNCTIONS] ON [TBITEMS].[FUNCTION_ID] = [TBFUNCTIONS].[GUID]
		
GO
