IF NOT EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='PRC_EMP_SRV_EMAIL_CONFIG') 
BEGIN
CREATE TABLE [dbo].[PRC_EMP_SRV_EMAIL_CONFIG](
	[CD_EMP] [int] NOT NULL,
	[END_EMAIL] [nvarchar](100) NULL,
	[USU_EMAIL] [nvarchar](50) NULL,
	[SENHA_EMAIL] [nvarchar](50) NULL,
	[SMTP] [nvarchar](100) NULL,
	[PORTA] [int] NULL,
	[FLAG_USA_SSL] [int] NULL,
	[TP_SSL] [int] NULL,
	[FLAG_USA_TLS] [int] NULL,
 CONSTRAINT [PK_PRC_EMP_SRV_EMAIL_CONFIG] PRIMARY KEY CLUSTERED 
(
	[CD_EMP] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY];

ALTER TABLE [dbo].[PRC_EMP_SRV_EMAIL_CONFIG] ADD  CONSTRAINT [DF_PRC_EMP_SRV_EMAIL_CONFIG_PORTA]  DEFAULT ((0)) FOR [PORTA];

ALTER TABLE [dbo].[PRC_EMP_SRV_EMAIL_CONFIG] ADD  CONSTRAINT [DF_PRC_EMP_SRV_EMAIL_CONFIG_FLAG_USA_SSL]  DEFAULT ((0)) FOR [FLAG_USA_SSL];

ALTER TABLE [dbo].[PRC_EMP_SRV_EMAIL_CONFIG] ADD  CONSTRAINT [DF_PRC_EMP_SRV_EMAIL_CONFIG_TP_SSL]  DEFAULT ((0)) FOR [TP_SSL];

ALTER TABLE [dbo].[PRC_EMP_SRV_EMAIL_CONFIG] ADD  DEFAULT ((0)) FOR [FLAG_USA_TLS];

ALTER TABLE [dbo].[PRC_EMP_SRV_EMAIL_CONFIG]  WITH CHECK ADD  CONSTRAINT [FK_PRC_EMP_SRV_EMAIL_CONFIG_PRC_EMP] FOREIGN KEY([CD_EMP])
REFERENCES [dbo].[PRC_EMP] ([CD_EMP])
ON UPDATE CASCADE
ON DELETE CASCADE;

ALTER TABLE [dbo].[PRC_EMP_SRV_EMAIL_CONFIG] CHECK CONSTRAINT [FK_PRC_EMP_SRV_EMAIL_CONFIG_PRC_EMP]
END;


