Tables [dbo].[EquipmentDocument]
Properties
PropertyValue
CollationSQL_Latin1_General_CP1_CI_AS
Row Count (~)0
Created8:34:15 AM Friday, December 7, 2018
Last Modified9:01:32 AM Friday, November 22, 2024
Columns
NameData TypeMax Length (Bytes)Allow NullsIdentityDefault
Cluster Primary Key PK_EquipmentDocument: EquipmentDocumentIDEquipmentDocumentIDint4
No
1 - 1
Foreign Keys FK_EquipmentDocument_Equip: [dbo].[Equip].EquipmentFIDIndexes IX_EquipmentDocument_EquipmentFID: EquipmentFIDEquipmentFIDint4
No
DocumentNamevarchar(128)128
No
Foreign Keys FK_EquipmentDocument_SysUser: [dbo].[Sysuser].AttachedByFIDIndexes IX_EquipmentDocument_AttachedByFID: AttachedByFIDAttachedByFIDint4
No
AttachedOndatetime8
No
LastModifieddatetime8
No
ExternalImageFIDint4
No
Foreign Keys FK_EquipmentDocument_EquipmentDocumentType: [dbo].[EquipmentDocumentType].EquipmentDocumentTypeFIDEquipmentDocumentTypeFIDint4
No
DocumentDescriptionvarchar(64)64
Yes
DocumentNotesvarchar(256)256
Yes
Inactivebit1
No
((0))
Indexes Indexes
NameColumnsUnique
Cluster Primary Key PK_EquipmentDocument: EquipmentDocumentIDPK_EquipmentDocumentEquipmentDocumentID
Yes
IX_EquipmentDocument_AttachedByFIDAttachedByFID
IX_EquipmentDocument_EquipmentFIDEquipmentFID
Triggers Triggers
NameANSI Nulls OnQuoted Identifier OnOn
EquipmentDocumentDeleted
Yes
Yes
After Delete
Foreign Keys Foreign Keys
NameColumns
FK_EquipmentDocument_SysUserAttachedByFID->[dbo].[Sysuser].[SysUserID]
FK_EquipmentDocument_EquipmentDocumentTypeEquipmentDocumentTypeFID->[dbo].[EquipmentDocumentType].[EquipmentDocumentTypeID]
FK_EquipmentDocument_EquipEquipmentFID->[dbo].[Equip].[PriKey]
Permissions
TypeActionOwning Principal
GrantDeleteMssExec
GrantInsertMssExec
GrantSelectMssExec
GrantUpdateMssExec
SQL Script
CREATE TABLE [dbo].[EquipmentDocument]
(
[EquipmentDocumentID] [int] NOT NULL IDENTITY(1, 1),
[EquipmentFID] [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,
[EquipmentDocumentTypeFID] [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_EquipmentDocument_Inactive] DEFAULT ((0))
) ON [PRIMARY]
GO

-- Deletes any documents that are stored in the external document db that are linked to EquipmentDocuments getting deleted
create trigger [dbo].[EquipmentDocumentDeleted] on [dbo].[EquipmentDocument]
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].[EquipmentDocument] ADD CONSTRAINT [PK_EquipmentDocument] PRIMARY KEY CLUSTERED  ([EquipmentDocumentID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_EquipmentDocument_AttachedByFID] ON [dbo].[EquipmentDocument] ([AttachedByFID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_EquipmentDocument_EquipmentFID] ON [dbo].[EquipmentDocument] ([EquipmentFID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[EquipmentDocument] ADD CONSTRAINT [FK_EquipmentDocument_SysUser] FOREIGN KEY ([AttachedByFID]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
ALTER TABLE [dbo].[EquipmentDocument] ADD CONSTRAINT [FK_EquipmentDocument_EquipmentDocumentType] FOREIGN KEY ([EquipmentDocumentTypeFID]) REFERENCES [dbo].[EquipmentDocumentType] ([EquipmentDocumentTypeID])
GO
ALTER TABLE [dbo].[EquipmentDocument] ADD CONSTRAINT [FK_EquipmentDocument_Equip] FOREIGN KEY ([EquipmentFID]) REFERENCES [dbo].[Equip] ([PriKey])
GO
GRANT SELECT ON  [dbo].[EquipmentDocument] TO [MssExec]
GRANT INSERT ON  [dbo].[EquipmentDocument] TO [MssExec]
GRANT DELETE ON  [dbo].[EquipmentDocument] TO [MssExec]
GRANT UPDATE ON  [dbo].[EquipmentDocument] TO [MssExec]
GO
Uses