/****** OBJECT:  TABLE [DBO].[TENTACLE_SYNC_TABELAS]    SCRIPT DATE: 27/11/2019 15:17:21 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF OBJECT_ID('TENTACLE_SYNC_TABELAS') IS NULL 
BEGIN
CREATE TABLE [DBO].[TENTACLE_SYNC_TABELAS](
	[CD_CTR] [INT] IDENTITY(1,1) NOT NULL,
	[TABELA_ORIGEM] [VARCHAR](100) NOT NULL,
	[TABELA_ORIGEM_MONITORADA] [VARCHAR](100) NOT NULL,
	[TABELA_DESTINO] [VARCHAR](100) NOT NULL,
	[PK_TABELAS] [VARCHAR](100) NOT NULL,
	[FLAG_TABELA_MESTRE] [INT] NOT NULL,
	[CHANGE_TRACKING_TABELA_MESTRE] [BIGINT] NOT NULL,
	[PK_TABELAS_PG] [VARCHAR](100) NULL
) ON [PRIMARY]

ALTER TABLE [DBO].[TENTACLE_SYNC_TABELAS] ADD  CONSTRAINT [DF_TENTACLE_SYNC_TABELAS_FLAG_TABELA_MESTRE]  DEFAULT ((0)) FOR [FLAG_TABELA_MESTRE]

ALTER TABLE [DBO].[TENTACLE_SYNC_TABELAS] ADD  CONSTRAINT [DF_TENTACLE_SYNC_TABELAS_CHANGE_TRACKING_TABELA_MESTRE]  DEFAULT ((0)) FOR [CHANGE_TRACKING_TABELA_MESTRE]

ALTER TABLE [DBO].[TENTACLE_SYNC_TABELAS] ADD  CONSTRAINT [DF_TENTACLE_SYNC_TABELAS_PK_TABELAS_PG]  DEFAULT ('') FOR [PK_TABELAS_PG]
END
GO 


 IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'TENTACLE_SYNC_TABELAS' AND COLUMN_NAME = 'FLAG_TABELA_MESTRE') 
 BEGIN
       ALTER TABLE TENTACLE_SYNC_TABELAS ADD  FLAG_TABELA_MESTRE INT NOT NULL DEFAULT 0
	   ALTER TABLE TENTACLE_SYNC_TABELAS ADD  CHANGE_TRACKING_TABELA_MESTRE BIGINT NOT NULL DEFAULT 0
	   ALTER TABLE TENTACLE_SYNC_TABELAS ADD  PK_TABELAS_PG VARCHAR(100)  DEFAULT ''
	   
 
 END 