[dbo].[AccountProfileDocument]
CREATE TABLE [dbo].[AccountProfileDocument]
(
[AccountProfileDocumentID] [int] NOT NULL IDENTITY(1, 1),
[AccountProfileFID] [int] NOT NULL,
[DocumentName] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[AttachedByFID] [int] NOT NULL,
[AttachedOn] [datetime] NOT NULL,
[LastModified] [datetime] NOT NULL,
[ExternalImageFID] [int] NOT NULL,
[AccountProfileDocumentTypeFID] [int] NOT NULL,
[DocumentDescription] [varchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[DocumentNotes] [varchar] (256) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Inactive] [bit] NOT NULL CONSTRAINT [DF_AccountProfileDocument_Inactive] DEFAULT ((0))
) ON [PRIMARY]
GO
create trigger [dbo].[AccountProfileDocumentDeleted] on [dbo].[AccountProfileDocument]
after delete as
set nocount on
declare @theExternalDocumentImageIDs IntList
insert into @theExternalDocumentImageIDs
select deleted.ExternalImageFID
from deleted
where deleted.ExternalImageFID is not null
if( 0 < ( select count(*) from @theExternalDocumentImageIDs ) )
begin
declare @theDocDBName sysname
set @theDocDBName = dbo.GetDocDbName()
declare @theDeleteCommand nvarchar(max)
set @theDeleteCommand =
'delete ' + @theDocDBName + '..DocumentImage ' +
'from @inExternalDocumentImageIDs theExternalDocumentImageIDs ' +
'inner join ' + @theDocDBName + '..DocumentImage DocumentImage on theExternalDocumentImageIDs.Item = DocumentImage.DocumentImageID '
exec sp_executesql @theDeleteCommand, N'@inExternalDocumentImageIDs IntList readonly', @theExternalDocumentImageIDs
end
GO
ALTER TABLE [dbo].[AccountProfileDocument] ADD CONSTRAINT [PK_AccountProfileDocument] PRIMARY KEY CLUSTERED ([AccountProfileDocumentID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_AccountProfileDocument_AccountProfileFID] ON [dbo].[AccountProfileDocument] ([AccountProfileFID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_AccountProfileDocument_AttachedByFID] ON [dbo].[AccountProfileDocument] ([AttachedByFID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[AccountProfileDocument] ADD CONSTRAINT [FK_AccountProfileDocument_AccountProfileDocumentType] FOREIGN KEY ([AccountProfileDocumentTypeFID]) REFERENCES [dbo].[AccountProfileDocumentType] ([AccountProfileDocumentTypeID])
GO
ALTER TABLE [dbo].[AccountProfileDocument] ADD CONSTRAINT [FK_AccountProfileDocument_AccountProfiles] FOREIGN KEY ([AccountProfileFID]) REFERENCES [dbo].[AccountProfiles] ([AccountProfileID])
GO
ALTER TABLE [dbo].[AccountProfileDocument] ADD CONSTRAINT [FK_AccountProfileDocument_SysUser] FOREIGN KEY ([AttachedByFID]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
GRANT SELECT ON [dbo].[AccountProfileDocument] TO [MssExec]
GRANT INSERT ON [dbo].[AccountProfileDocument] TO [MssExec]
GRANT DELETE ON [dbo].[AccountProfileDocument] TO [MssExec]
GRANT UPDATE ON [dbo].[AccountProfileDocument] TO [MssExec]
GO