IF NOT EXISTS (SELECT 1 FROM SYSOBJECTS WHERE xtype='U' AND name='CONFIGURACAOBOLETOEMAIL') 
BEGIN
CREATE TABLE CONFIGURACAOBOLETOEMAIL 
(
  ID INT Identity(1,1) NOT NULL,
	TEMPOPROCESSAMENTO INT,
	DATAINICIO DATE,
	DETALHAMENTO NUMERIC (1,0) DEFAULT 0,
	SERVIDORSMTP VARCHAR (254),
	PORTA VARCHAR (10),
	USUARIO	VARCHAR (254),
	SENHA VARCHAR (254),
	PROTOCOLO NUMERIC (1,0),
	ASSUNTO	VARCHAR (254),	
	MENSAGEM VARCHAR (1000),
	URLLOGOTIPO VARCHAR(254),
	URLIMAGENSCODIGOBARRAS VARCHAR(254),
	RUSUARIO INT,			
	ATUALIZADOEM DATETIME 
)
ALTER TABLE CONFIGURACAOBOLETOEMAIL ADD CONSTRAINT PK_CONFIGURACAOBOLETOEMAIL PRIMARY KEY CLUSTERED(Id)
END
GO

IF NOT EXISTS (SELECT 1 FROM SYSOBJECTS WHERE xtype='U' AND name='CONTROLEBOLETOEMAIL') 
BEGIN
CREATE TABLE CONTROLEBOLETOEMAIL 
(
	ID INT Identity(1,1) NOT NULL,
	NUMPED INT,
	NUMORD	INT, 
	RDOCDEORIGEM INT, 
	EMISSAO	DATETIME,
	DATAENVIO	DATETIME,
	SITUACAOENVIO NUMERIC (1,0) DEFAULT 0,
	SITUACAOERRO NUMERIC (1,0) DEFAULT 0
)
ALTER TABLE CONTROLEBOLETOEMAIL ADD CONSTRAINT PK_CONTROLEBOLETOEMAIL PRIMARY KEY CLUSTERED(Id)
END
GO
IF NOT EXISTS (SELECT 1 FROM SYSOBJECTS WHERE xtype='U' AND name='HISTORICOBOLETOEMAIL') 
CREATE TABLE HISTORICOBOLETOEMAIL 
(
	RIDCONTROLEBOLETOEMAIL	INT,
	RUSUARIO INT,
	ATUALIZADOEM DATETIME, 
	HISTORICO VARCHAR(1000)
)
GO
