IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[Maillog]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE [dbo].[Maillog](
	 [MaillogID] [int] IDENTITY(1,1) NOT NULL,
	 [DateStamp] [datetime] NOT NULL,
	 [UserIDNumber] [int] NOT NULL,
	 [FromAddress] [varchar](255) NULL,
	 [ToAddress] [varchar](255) NULL,
	 [CCAddress] [varchar](255) NULL,
	 [BCCAddress] [varchar](255) NULL,
	 [Subject] [varchar](255) NULL,
	 [Body] [varchar](max) NULL,
	 [Result] [varchar](255) NULL,
	 [ErrorMessage] [varchar](max) NULL,
	 [AttachmentFiles] [varchar](max) NULL,
 	 [SMTPPort] [int] NULL,
	 [SMTPServer] [varchar](255) NULL,
	 [SMTPUsername] [varchar](255) NULL,
	 [SMTPPassword] [varchar](255) NULL,
	 [SMTPUseAuthentication] [bit] NULL,
	 [SMTPUseEHLO] [bit] NULL,
	 [SMTPUseSASL] [bit] NULL,
	 [SMTPTLSSSLMode] [int] NULL,
  CONSTRAINT [PK_Maillog] PRIMARY KEY CLUSTERED ([MaillogID] ASC)) ON [PRIMARY]

  ALTER TABLE [dbo].[Maillog] ADD  DEFAULT (getdate()) FOR [DateStamp]
END
GO

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[Signature]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[Signature](
	[SignatureID] [int] IDENTITY(1,1) NOT NULL,
	[SignatureType] [int] NOT NULL,
	[SignatureTextType] [int] NOT NULL,
	[Signature] [nvarchar](max) NULL,
 CONSTRAINT [PK_Signature] PRIMARY KEY CLUSTERED 
(
	[SignatureID] ASC
)) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[PersonnelSignatureXtab]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE [dbo].[PersonnelSignatureXtab](
  	[FK_UserIDNumber] [int] NOT NULL,
	[FK_SignatureID] [int] NOT NULL,
   CONSTRAINT [PK_PersonnelSignatureXtab] PRIMARY KEY CLUSTERED 
  (
	[FK_UserIDNumber] ASC,
	[FK_SignatureID] ASC
  )) ON [PRIMARY]

ALTER TABLE [dbo].[PersonnelSignatureXtab]  WITH NOCHECK ADD  CONSTRAINT [FK_PersonnelSignatureXtab_Personel] FOREIGN KEY([FK_UserIDNumber]) REFERENCES [dbo].[PERSONEL] ([UserIDNumber])
ALTER TABLE [dbo].[PersonnelSignatureXtab] CHECK CONSTRAINT [FK_PersonnelSignatureXtab_Personel]
ALTER TABLE [dbo].[PersonnelSignatureXtab]  WITH NOCHECK ADD  CONSTRAINT [FK_PersonnelSignatureXtab_Signature] FOREIGN KEY([FK_SignatureID]) REFERENCES [dbo].[Signature] ([SignatureID])
ALTER TABLE [dbo].[PersonnelSignatureXtab] CHECK CONSTRAINT [FK_PersonnelSignatureXtab_Signature]
END
GO

