sp_MSforeachtable 排序依据

sp_MSforeachtable order by(sp_MSforeachtable 排序依据)
本文介绍了sp_MSforeachtable 排序依据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在使用 sp_MSforeachtable 来获取数据库中特定表的行数.我想要这些按名称排序.

I am using sp_MSforeachtable to get a rowcount of specific tables in my database. I want these ordered by name.

如何向 sp_MSforeachtable 添加 ORDER BY 子句?

How do I add an ORDER BY clause to sp_MSforeachtable?

推荐答案

我知道这个问题已经有 10 多年的历史了,但它有超过 3000 次访问和一堆错误答案.我将重新调整 Chris R. 的答案,希望将其标记为已接受的答案,而不是过于复杂的半页 SQL 或你不能"的答案.我带着完全相同的问题来到这里,所以它仍然是相关的,显然并不简单.

I understand this question is over 10 years old, but it has over 3000 visits and a bunch of wrong answers. I'm going to repurpose Chris R.'s answer in hopes of getting this marked as the accepted answer, instead of overly-complicated half-pages of SQL or "you can't" answers. I came here with the exact same question so it's still relevant and obviously not simple.

使用@whereand参数指定一个ORDER BY子句,该参数的内容被附加到内部SELECT的末尾> 通过存储过程中的简单 + @whereand 语句.而在 ORDER BY 1 中使用 1 表示按第一列排序.

Use the @whereand parameter to specify an ORDER BY clause, The contents of that parameter are tacked on to the end of the internal SELECT statement via a simple + @whereand in the stored proc. And using 1 in ORDER BY 1 means to order by the first column.

sp_MSforeachtable @command1='SELECT COUNT(*) AS ''?'' FROM ?', @whereand = 'ORDER BY 1'

这篇关于sp_MSforeachtable 排序依据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
SQL query to group by day(按天分组的 SQL 查询)
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)