惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The GitHub Blog
The GitHub Blog
J
Java Code Geeks
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Vercel News
Vercel News
腾讯CDC
博客园 - 聂微东
The Cloudflare Blog
F
Fortinet All Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
Last Week in AI
Last Week in AI
B
Blog

Donghai's Blog

使用DBeaver连接Dynamics 365 Dataverse | Donghai C# 技术备忘 - LINQ | Donghai 为Astro站点添加Google Analytics | Donghai C# 技术备忘 - LINQ - Donghai’s Blog 20260819 说些什么 | Donghai Dynamics 365 interview questions | Donghai C# 技术备忘 (1) | Donghai Dynamics 365 事件框架、事件执行管道 | Donghai 马拉松配速表 | Donghai 马拉松赛事分级 | Donghai 抖音创作日志(2026年) | Donghai 2026年跑步日志(5月开始) | Donghai 2FA | Donghai 初尝Github Actions | Donghai AstroPaper主题添加Waline评论 | Donghai Dynamics 365集中视图/聚焦视图/Focused View | Donghai AstroPaper主题添加GitHub风格的Markdown警告框 | Donghai AstroPaper主题自定义记录 | Donghai 我日常收藏的优质网站资源导航(持续更新) | Donghai 如何从归档页批量获取URL并提交到Bing Webmaster Tools | Donghai PaperMod 使用 Zeoseven 自定义网页字体 | Donghai 我常用的Prompt | Donghai Hugo默认时区导致本地预览文章不显示 | Donghai 通过手动提交工单解决Bing不收录网站问题 | Donghai 如何访问 Power BI 管理门户(Power BI Admin Portal) | Donghai 还在手敲时间戳?Win11输入法一个技巧,秒输当前时间戳 | Donghai 工作术语备忘录(持续更新) | Donghai 使用XrmToolBox导出安全角色表级权限到Excel | Donghai 24年的年终总结 | Donghai World笔记 | Donghai
在Dynamics 365项目中常用的SQL语句(持续更新) | Donghai
Donghai · 2025-02-17 · via Donghai's Blog

本文针对 Dynamics 365 的日常运维和管理需求,整理些实用的 SQL 查询脚本

Table of contents

Open Table of contents
  • 1. 查询指定实体下的所有系统视图
  • 2. 检索系统报表清单与元数据
  • 3. 查询Annotation容量
  • 4. 查询特定安全角色的所有分配用户
  • 5. 查看用户分配了哪些安全角色

1. 查询指定实体下的所有系统视图

该查询用于快速检索 Dynamics 365 中特定实体(如客户、联系人)下配置的所有系统视图

-- Example: Query all views and their Ids under the Account entity
SELECT
    v.SavedQueryId AS 'View Id',
    v.Name AS 'View name',
    v.returnedtypecode AS 'Owning entity'
FROM
    SavedQuery v
WHERE
    returnedtypecode = 'account'

2. 检索系统报表清单与元数据

通过查询报表主表,可以获取环境中所有报表的详细信息,包括创建人、创建时间及文件名称,常用于报表资产盘点或清理闲置报表

SELECT reportid,
       name,
       filename,
       description,
       owneridname,
       componentstatename,
       createdon,
       createdbyname
FROM   report;

3. 查询Annotation容量

-- Warning: May freeze if data is large
-- 1 MB = 1024 * 1024 Bytes = 1,048,576 Bytes
SELECT SUM(filesize) / 1048576 AS TotalFileSizeMB
FROM   annotation;

4. 查询特定安全角色的所有分配用户

此脚本用于审计,清晰列出拥有某个特定安全角色(如“售前顾问”)的所有用户

SELECT
    systemuser.fullname AS UserFullName,
    systemuser.domainname AS DomainName,
    systemuser.systemuserid AS UserId,
    role.name AS RoleName
FROM
    systemuserroles
INNER JOIN
    systemuser ON systemuserroles.systemuserid = systemuser.systemuserid
INNER JOIN
    role ON systemuserroles.roleid = role.roleid
WHERE
    role.name = 'Pre-sales' -- Security role name

Query result:

UserFullNameDomainNameUserIdRoleName
Zhang Sanzhangsan@sample.comxxx..Pre-sales
Li Silisi@sample.comxxx..Pre-sales

5. 查看用户分配了哪些安全角色

SELECT
    su.fullname AS UserFullName,
    su.domainname AS DomainName,
    su.systemuserid AS UserId,
    STRING_AGG(r.name, ', ') AS RoleNames
FROM
    systemuserroles sur
INNER JOIN
    systemuser su ON sur.systemuserid = su.systemuserid
INNER JOIN
    role r ON sur.roleid = r.roleid
GROUP BY
    su.fullname,
    su.domainname,
    su.systemuserid
ORDER BY
    su.fullname

查询结果:

UserFullNameDomainNameUserIdRoleName
Zhang Sanzhangsan@sample.comxxxPre-sales, Sales Manager
Li Silisi@sample.comxxxPre-sales, Sales Director, System Administrator

(完)

如果这篇文章刚好帮到了你,欢迎请我喝杯咖啡