Some of the sample data didn't get posted in the proper place. The 30 minute cut-off didn't allow me to edit it further. Here's the sample data with it's table:
AppPermission:
AppGroup:
AppUser:
AppGroupPermission:
AppUserGroup:
Sample SQL Queries:
To get permissions for "user2":
SELECT AppGroupPermission.groupName, AppGroupPermission.permissionName
FROM AppGroupPermission
INNER JOIN AppUserGroup
ON AppGroupPermission.groupName = AppUserGroup.groupName
WHERE AppUserGroup.userId = 'user2'
To get permissions for "user2" along with the description of the permissions:
SELECT t2.groupName, t2.permissionName, AppPermission.description
FROM AppPermission
INNER JOIN
(SELECT AppGroupPermission.groupName, AppGroupPermission.permissionName
FROM AppGroupPermission
INNER JOIN AppUserGroup
ON AppGroupPermission.groupName = AppUserGroup.groupName
WHERE AppUserGroup.userId = 'user2') t2
ON t2.permissionName = AppPermission.name
Here's how to create a table programmatically:
Need to add Imports System.Data.SqlClient
Public Sub AppPermissionTbl()
Try
Using cn As New SqlConnection(connectStr)
Dim sqlText As String = String.Empty
sqlText = "CREATE TABLE AppPermission (name nvarchar(50) NOT NULL "
sqlText += "CONSTRAINT PK_AppPermission_name PRIMARY KEY, "
sqlText += "description nvarchar(100))"
'open connection
cn.Open()
'create new SqlCommand
Using sqlCmd As New SqlCommand(sqlText, cn)
'execute
sqlCmd.ExecuteNonQuery()
End Using
System.Windows.Forms.MessageBox.Show("Table created: AppPermission", "Table Created.", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Using
Catch ex As SqlClient.SqlException
System.Windows.Forms.MessageBox.Show("Error:: AppPermissionTbl: " & ex.Message, "Error - Create Table", MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch ex As Exception
System.Windows.Forms.MessageBox.Show("Error:: AppPermissionTbl: " & ex.Message, "Error - Create Table", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
There are documents attached below (in rich text format) that contain …