Good day. Trying to create a view in MS SQL that retrieves user data MS Dynamics CRM. I just need to extract the name of the employee and to correlate it with the identifier of one particular group. But the problem is that I can not find a relation with the security roles. Please give an example.
The table you are looking for is SystemUserRoles
select systemuser.firstname, systemuser.lastname, role.name, role.*
from systemuser
join SystemUserRoles on systemuser.systemuserid = systemuserroles.SystemUserId
join [role] on systemuserroles.roleid = [role].roleid
Related
Our Security group is asking for us to have Snowflake audit records ingested into our on prem SIEM by the end of the quarter. I've found the information_schema.login_history records but I'm struggling to find anything else that the SIEM might want (privilege usage, etc). Any tips on relevant views or functions would be appreciated.
some tables can be used to understand query & login attempts by Snowflake users along with various dimensions. For details take a look at:
https://docs.snowflake.net/manuals/sql-reference/functions/login_history.html
https://docs.snowflake.net/manuals/sql-reference/functions/query_history.html
Here are some of the SNOWFLAKE ACCOUNT_USAGE SCHEMA QUERIES that may come handy.
Access_History ,Query_History will help to find out who and How the Snowflake DB is been accessed and Query History will show the queries executed ,Role ,Warehouse,start time ,end time etc.
Also try to login to Snowsight get the full lineage of a specific Role.
--TO FIND THE ACTIVE USERS IN THE ACCOUNT--
SELECT FIRST_NAME,LAST_NAME,DISPLAY_NAME from "SNOWFLAKE"."ACCOUNT_USAGE"."USERS"
WHERE DELETED_ON IS NULL GROUP BY FIRST_NAME,LAST_NAME,DISPLAY_NAME
ORDER BY FIRST_NAME DESC;
--TO FIND THE ACTIVE USERS AND ROLES IN THE ACCOUNT--
SELECT ROLE,GRANTEE_NAME,GRANTED_BY FROM "SNOWFLAKE"."ACCOUNT_USAGE"."GRANTS_TO_USERS"
WHERE DELETED_ON IS NULL
GROUP BY ROLE,GRANTEE_NAME,GRANTED_BY
ORDER BY GRANTEE_NAME DESC;
--TO FIND THE ACTIVE GRANTS ON ROLES TO OBJECTS--
SELECT PRIVILEGE,TABLE_CATALOG,GRANTEE_NAME,GRANTED_BY FROM "SNOWFLAKE"."ACCOUNT_USAGE"."GRANTS_TO_ROLES"
WHERE DELETED_ON IS NULL
GROUP BY PRIVILEGE,TABLE_CATALOG,GRANTEE_NAME,GRANTED_BY
ORDER BY TABLE_CATALOG;
I have a table in an Azure SQL Database with access to the table granted through Azure AD groups.
One of the columns is a ‘category level’.
Each AD group has a category level and each group should only be able to read rows at their category level OR below.
EG AD group ‘group 3’ should only be able to select rows with a category level of 3,2,1. AD group ‘group 6’ will select rows with category level 6,5,4,3,2,1
I am wondering if there is a way to apply row level security that will allow this scenario?
Results I'd like to achieve: One record for each customer.
Number of tables: 3 (Account Master, MeterStatus, Codes.MeterStatus)
Hello, I'm trying to find one record for each customer in the following tables, Account Master, MeterStatus, Codes.MeterStatus. Account Master contains customers who are active (need to find here if its available), Meterstatus table contains customers who have been enrolled in our system, but might not have made it to active status, and codes.meterstatus is simply used to decipher codes that are located in meterstatus table.
I've already tried the following variations, but they have not provided the results I expected.
Select *
FROM [xx].[dbo].[AccountMaster] EAM
full join [xx].[Link].[MeterStatus] MS on ms.UAN = eam.UAN
left join xx.codes.MeterStatus on ms.MeterStatus = MeterStatus.MeterStatus
where eam.UAN in ('055013920') or ms.UtilityAccountNumber in ('055013920')
and ms.MeterStatus not in ('4','5')
FROM [xx].[Link].[MeterStatus] MS
left join xx.dbo.AccountMaster EAM on ms.UAN = eam.UAN
left join xx.codes.MeterStatus on ms.MeterStatus = MeterStatus.MeterStatus
where ms.UANin ('055013920')
and ms.MeterStatus not in ('4','5')
Using SQL Server 2008, I am trying to figure out how to create a query that returns a pivot table with a standard many-to-many relationship. This relationship defines which users belong to which roles and I want the table to list the user name along the side and the role names across the top. The ultimate goal is to have this output in SQL Server Reporting Services, so it doesn't matter if SQL server generates the pivot results, or SSRS generates the results (is one method better than the other?). Here is my sample schema:
Users Table:
UserID
UserName
Rights Table:
RightID
RightName
RightsMembership Table:
UserID
RightID
I want the following output as a report in SSRS. Any help is appreciated.
RightOne RightTwo RightThree RightFour
jdoe X X
mjane X X
ssmith X X X
FYI: Roles can be added, so I would prefer not to have to hard code the role name or count in the query.
I Don't Know about the Pivot Tables but you can achieve this in the SSRS as below
Select UserName,
RightName
From users u INNER JOIN RightMembership rm on rm.UserID = u.UserID
INNER JOIN Rights r on rm.RightID = r.RightID
Use this query as the Stored Procedure or Query and the Order By Accordingly and
Create the Dataset and Datasource
Insert matrix in the report
In the rows select the UserName field From the Created Dataset
In the columns select the RightName field from the created Dataset
In the Data use this Expression below then you will get the desired output
=IIF(Fields!UserName.Value = nothing,nothing,"X") As the Data in the matrix
Currently I am designing a small twitter/facebook kind of system, where in a user should be able to see his friends latest activities.
I am using ASP.NET with MySQL database.
My Friendships table is as follows:
|Friendshipid|friend1|Friend2|confirmed|
Friend1 and Friend2 in the above table are userids.
User activities table design following:
|activityId|userid|activity|Dated|
Now, I am looking for best way to query the latest 50 friend activities for a user.
For example, let's say if Tom logs into the system, he should be able to see latest 50 activities among all his friends.
Any pointers on the best practices, a query or any information is appreciated.
It largely depends on what data is stored in the Friendships table. For example, what order are the Friend1 and Friend2 fields stored in? If, for the fields (friend1, friend2) the tuple (1, 2) exists, will (2, 1) exist also?
If this is not the case, then this should work:
SELECT activities.*
FROM Activities
INNER JOIN Friendships ON userid = friend1 OR userid = friend2
WHERE activity.userid != [my own id]
AND confirmed = TRUE
LIMIT 50;
If you have database performance concern, you may redefine the friendship table as following:
friendshipid, userid, friendid, confirmed
When you query the latest 50 activities, the SQL would be:
SELECT act.*
FROM Activities AS act
INNER JOIN
Friendships AS fs
ON fs.friendid = act.userid
AND fs.user_id = 'logon_user_id'
AND confirmed = TRUE
ORDER BY act.dated DESC
LIMIT 50;
And if there is a index on Friendships(userid) column, it would give the database the chance to optimize the query.
The friendship table redefined needs to create two tuples when a friendship occur, but it still obey the rule of business, and, has performance benefit when you need it.