CREATE TABLE [dbo].[ATProcessDocumentTemplateRight]
(
	[ProcessObjectId]    UNIQUEIDENTIFIER NOT NULL,
    [AllowRights] INT              NOT NULL,
    [DocumentTemplateObjectid]  UNIQUEIDENTIFIER NOT NULL, 
    CONSTRAINT [FK_ATProcessDocumentTemplateRights_ATProcessDefinition] FOREIGN KEY (ProcessObjectId) REFERENCES ATProcessDefinition(ObjectId), 
    CONSTRAINT [FK_ATProcessDocumentTemplateRights_ATDocumentCabinet] FOREIGN KEY ([DocumentTemplateObjectid]) REFERENCES ATDocumentCabinet(ObjectId),
    CONSTRAINT [FK_ATProcessDocumentTemplateRights_ATRightAllowRight] FOREIGN KEY ([AllowRights]) REFERENCES [dbo].[ATRightAllowRight] ([Id]), 
    CONSTRAINT [PK_ATProcessDocumentTemplateRight] PRIMARY KEY (ProcessObjectId, AllowRights, DocumentTemplateObjectid) 
)

GO

CREATE INDEX [IX_ATProcessDocumentTemplateRights_ProcessObjectId] ON [dbo].[ATProcessDocumentTemplateRight] (ProcessObjectId)
