CREATE TABLE [dbo].[ATRight] (
    [UserGuid]    UNIQUEIDENTIFIER NOT NULL,
    [ObjectType]  INT              NOT NULL,
    [AllowRights] INT              NOT NULL,
    [ObjectGuid]  UNIQUEIDENTIFIER NOT NULL,
    CONSTRAINT [PK_ATRight] PRIMARY KEY ([UserGuid], [ObjectType], [AllowRights], [ObjectGuid]),
    CONSTRAINT [FK_ATRight_ATUser] FOREIGN KEY ([UserGuid]) REFERENCES [dbo].[ATUser] ([ObjectId]),
    CONSTRAINT [FK_ATRight_ATRightObjectType] FOREIGN KEY ([ObjectType]) REFERENCES [dbo].[ATRightObjectType] ([Id]),
    CONSTRAINT [FK_ATRight_ATRightAllowRight] FOREIGN KEY ([AllowRights]) REFERENCES [dbo].[ATRightAllowRight] ([Id]),
);

GO
CREATE NONCLUSTERED INDEX [ATRight_Composite1]
    ON [dbo].[ATRight]([ObjectType] ASC, [ObjectGuid] ASC, [UserGuid] ASC);


GO
CREATE NONCLUSTERED INDEX [ATRight_Composite2]
    ON [dbo].[ATRight]([AllowRights] ASC, [UserGuid] ASC, [ObjectGuid] ASC);


GO
CREATE NONCLUSTERED INDEX [ATRight_UserGuid]
    ON [dbo].[ATRight]([UserGuid] ASC);

