IF OBJECT_ID('TENTACLE_SYNC_VERSAO') IS NULL
BEGIN

	CREATE TABLE [dbo].[TENTACLE_SYNC_VERSAO](
		[CLIENT_ID] [int]  NOT NULL,
		[TABELA] [varchar](100) NOT NULL,
		[LAST_VERSION] [bigint] NULL,
		[LAST_TIME] [datetime] NULL,
	CONSTRAINT [PK_TENTACLE_SYNC_VERSAO] PRIMARY KEY CLUSTERED 
	(
		[CLIENT_ID], [TABELA] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY])
	
END

GO

IF NOT EXISTS (SELECT * FROM SYS.foreign_keys WHERE NAME = 'FK_TENTACLE_SYNC_VERSAO_TENTACLE_SYNC_CLIENT_CLIENT_ID')
BEGIN
	ALTER TABLE TENTACLE_SYNC_VERSAO ADD CONSTRAINT FK_TENTACLE_SYNC_VERSAO_TENTACLE_SYNC_CLIENT_CLIENT_ID FOREIGN KEY (CLIENT_ID) REFERENCES TENTACLE_SYNC_CLIENT(ID)
END
