我正在尝试创建一个脚本,以查找sybase ase中某些表的行数。 我已经使用了以下-
set nocount on
go
set proc_return_status off
go
select count(*) from schemaname.tablename1
select count(*) from schemaname.tablename2
select count(*) from schemaname.tablename3
go
现在它给了我如下输出
456
768
321
我想要的是在计数旁边添加一个表名。就像下面的
456 tablename1
768 tablename2
321 tablename3
请在相同的地方指导我
最好的问候,
Debadtya
答案 0 :(得分:1)
类似于@aF编写的内容,但更加精致。
select count(*) as rCount, 'tablename1' as tableName from tablename1
union
select count(*), 'tablename2' from tablename2
union
select count(*), 'tablename3' from tablename3
答案 1 :(得分:-1)
您可以像这样使用count(*):
set nocount on
go
select count(*), 'tablename1' from dbname.owner.tablename1
go
select count(*), 'tablename2' from dbname.owner.tablename2
go
select count(*), 'tablename3' from dbname.owner.tablename3
go
或者您可以使用统计信息快速获取价值:
use dbname
go
set nocount on
go
select row_count(db_id(), object_id('tablename1')), 'tablename1' from owner.tablename1
go
select row_count(db_id(), object_id('tablename2')), 'tablename2' from owner.tablename2
go
select row_count(db_id(), object_id('tablename3')), 'tablename3' from owner.tablename3
go