IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'controlelog'))
BEGIN

CREATE TABLE [dbo].[controlelog](
[idcontrolelog] [bigint] IDENTITY(1,1) NOT NULL PRIMARY KEY,
[bdname] [varchar](255) NULL,
[tabela] [varchar](255) NULL);

DECLARE @banco VARCHAR(255) = (SELECT DB_NAME());

INSERT INTO [dbo].[controlelog] VALUES (@banco, N'oldbacklog');

CREATE TABLE [dbo].[actionlog](
[IDACTION] [bigint] IDENTITY(1,1) NOT NULL PRIMARY KEY,
[IDEMPRESA] [bigint] NULL,
[FORM] [varchar](30) NULL,
[DESCRICAO] [varchar](50) NULL,
[ACAO] [varchar](200) NULL,
[IDNAME] [varchar](30) NULL,
[ID] [bigint] NULL,
[IDUSUARIO] [bigint] NULL,
[DATA] [datetime] NULL,
[historico] [VARCHAR](MAX) NULL,
[maquina] [VARCHAR](100) NULL);

CREATE TABLE [dbo].[oldbacklog](
[IDBACKLOG] [bigint] IDENTITY(1,1) NOT NULL PRIMARY KEY,
[IDEMPRESA] [bigint] NULL,
[FORM] [varchar](30) NULL,
[DESCRICAO] [varchar](50) NULL,
[HISTORICO] [text] NULL,
[IDNAME] [varchar](30) NULL,
[ID] [bigint] NULL,
[INCLUINDO] [numeric](1, 0) NULL,
[IDUSUARIO] [bigint] NULL,
[DATA] [datetime] NULL);

END