[dbo].[PersonnelDocument]
CREATE TABLE [dbo].[PersonnelDocument]
(
[PersonnelDocumentID] [int] NOT NULL IDENTITY(1, 1),
[PersonnelFID] [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,
[PersonnelDocumentTypeFID] [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_PersonnelDocument_Inactive] DEFAULT ((0))
) ON [PRIMARY]
GO
create trigger [dbo].[PersonnelDocumentDeleted] on [dbo].[PersonnelDocument]
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].[PersonnelDocument] ADD CONSTRAINT [PK_PersonnelDocument] PRIMARY KEY CLUSTERED ([PersonnelDocumentID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_PersonnelDocument_AttachedByFID] ON [dbo].[PersonnelDocument] ([AttachedByFID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_PersonnelDocument_PersonnelFID] ON [dbo].[PersonnelDocument] ([PersonnelFID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[PersonnelDocument] ADD CONSTRAINT [FK_PersonnelDocument_SysUser2] FOREIGN KEY ([AttachedByFID]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
ALTER TABLE [dbo].[PersonnelDocument] ADD CONSTRAINT [FK_PersonnelDocument_PersonnelDocumentType] FOREIGN KEY ([PersonnelDocumentTypeFID]) REFERENCES [dbo].[PersonnelDocumentType] ([PersonnelDocumentTypeID])
GO
ALTER TABLE [dbo].[PersonnelDocument] ADD CONSTRAINT [FK_PersonnelDocument_SysUser] FOREIGN KEY ([PersonnelFID]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
GRANT SELECT ON [dbo].[PersonnelDocument] TO [MssExec]
GRANT INSERT ON [dbo].[PersonnelDocument] TO [MssExec]
GRANT DELETE ON [dbo].[PersonnelDocument] TO [MssExec]
GRANT UPDATE ON [dbo].[PersonnelDocument] TO [MssExec]
GO