当我运行查询时,我得到3行,行和表不等于我的行。我数了一下,我总共有222行。当我运行代码时,我只得到63并返回其他3行。我只应该有一排。似乎是当我放入最大值它会抛出一切。我应该总计所有表,获取总行数,获取最后一次更新数据库以及上次执行存储过程。我无法使用CROSS JOIN
因为我知道它可以使用它。还有其他想法吗?非常感谢!
SELECT
COUNT(SCHEMA_NAME()) AS TableCount,
SUM(SysPartn.Rows) AS 'Total rows in DB',
MAX(SysObj.modify_date) AS 'Last time updated',
(SysExProcStats.last_execution_time) AS 'Last time Executed'
FROM sys.objects AS SysObj
INNER JOIN sys.partitions AS SysPartn ON SysObj.object_id = SysPartn.object_id
INNER JOIN sys.dm_exec_procedure_stats AS SysExProcStats ON SysObj.object_id = SysExProcStats.object_id
WHERE SysObj.type = 'U'
GROUP BY SysExProcStats.last_execution_time
答案 0 :(得分:0)
您可以使用 LEFT JOIN :
SELECT
COUNT(SCHEMA_NAME()) AS TableCount,
SUM(SysPartn.Rows) AS 'Total rows in DB',
MAX(SysObj.modify_date) AS 'Last time updated',
(SysExProcStats.last_execution_time) AS 'Last time Executed'
FROM sys.objects AS SysObj
LEFT JOIN sys.partitions AS SysPartn ON SysObj.object_id = SysPartn.object_id
LEFT JOIN sys.dm_exec_procedure_stats AS SysExProcStats ON SysObj.object_id = SysExProcStats.object_id
WHERE SysObj.type = 'U'
GROUP BY SysExProcStats.last_execution_time