I have 3 tables:
Role
------
[Id],
[Name]
Scope
------
[Id],
[Name]
RoleScope
------
[RoleId],
[ScopeId],
[View],
[Add],
[Edit],
[Delete],
This is the relation many to many.
I have also the view which shows me that relation
CREATE VIEW View_RolesWithScopes
AS
SELECT
[Role].Id AS RoleId,
[Role].[Name] AS RoleName,
[RoleScope].ScopeId,
[Scope].[Name] AS ScopeName,
[RoleScope].[View],
[RoleScope].[Add],
[RoleScope].[Edit],
[RoleScope].[Delete]
FROM
dbo.[Role] [Role]
LEFT JOIN dbo.RoleScope [RoleScope] ON [RoleScope].RoleId = [Role].Id
LEFT JOIN dbo.Scope [Scope] ON [Scope].Id = [RoleScope].ScopeId
How to update this view to display record even there is no relation between in RoleScope
Example:
Role
------
Id | Name
1 | Role1
2 | Role2
Scope
------
Id | Name
1 | Scope1
2 | Scope2
3 | Scope3
RoleScope
------
RoleId | ScopeId | View | Add | Edit | Delete
1 | 1 | 1 | 1 | 1 | 0
1 | 2 | 1 | 0 | 1 | 0
Current result:
View_RolesWithScopes
------
RoleId | ScopeId | View | Add | Edit | Delete
1 | 1 | 1 | 1 | 1 | 0
1 | 2 | 1 | 0 | 1 | 0
2 | NULL | NULL | NULL| NULL | NULL
Expected result:
View_RolesWithScopes
------
RoleId | ScopeId | View | Add | Edit | Delete
1 | 1 | 1 | 1 | 1 | 0
1 | 2 | 1 | 0 | 1 | 0
1 | 3 | 0 | 0 | 0 | 0
2 | 1 | 0 | 0 | 0 | 0
2 | 2 | 0 | 0 | 0 | 0
2 | 3 | 0 | 0 | 0 | 0