我正在搜索一个SQL脚本,可用于确定给定数据库的任何表中是否有任何数据(即行计数).
我们的想法是在存在任何行(在任何数据库中)的情况下重新实现数据库.
所说的数据库是Microsoft SQL SERVER.
有人可以建议一个示例脚本吗?
如何列出数据库中每个表的行数.一些相当于
select count(*) from table1
select count(*) from table2
...
select count(*) from tableN
Run Code Online (Sandbox Code Playgroud)
我将发布一个解决方案,但欢迎其他方法
我有一个约150列的表.我想找到count(distinct(colName))每列的内容,但我想知道是否有办法这样做而不实际输入每个列名.
理想情况下我会使用,count(distinct(*))但这不起作用.
还有其他建议吗?
编辑:
如果这是我的表:
id col1 col2 col3 ...
01 10001 west north
02 10001 west south
03 10002 east south
04 10002 west north
05 10001 east south
06 10003 west north
Run Code Online (Sandbox Code Playgroud)
我正在寻找这个输出
count(distinct(id)) count(distinct(col1)) count(distinct(col2)) count(distinct(col3))
6 3 2 2
Run Code Online (Sandbox Code Playgroud)