IF EXISTS ( SELECT 1 FROM sys.tables t
            JOIN sys.schemas s ON t.schema_id = s.schema_id WHERE t.name IN ('Faturamento', 'Empresa') AND s.name = 'dbo'
)
BEGIN
    RAISERROR('ERRO: Estrutura incompatível com o banco do LinxPOS.', 16, 1)
    RETURN
END
SET NOCOUNT ON
GO
--============================================================================================================================
IF EXISTS (SELECT 1 FROM sys.tables t
			JOIN sys.schemas s ON t.schema_id = s.schema_id
			WHERE t.name IN ('Faturamento', 'Empresa') AND s.name = 'dbo'
)
BEGIN
    RAISERROR('ERRO: Estrutura incompatível com o banco do LinxPOS.', 16, 1)
    RETURN
END
BEGIN TRAN

BEGIN TRY

	DELETE FROM [dbo].[LJ_ETL_VERSAO_LOJA]

	INSERT INTO [dbo].[LJ_ETL_VERSAO_LOJA]
			   ([VERSAO]
			   ,[CODIGO_FILIAL]
			   ,[FILIAL])
		 VALUES
			   ('3.1.13'
			   ,'0000'
			   ,'DEFAULT')
	
	PRINT 'COMMIT';
	COMMIT;

END TRY
BEGIN CATCH

	PRINT 'ROLLBACK';
	ROLLBACK;

	SELECT ERROR_NUMBER() AS ErrorNumber, ERROR_MESSAGE() AS ErrorMessage

END CATCH
go
--===================================================================================================================