选择 Firebird 4.0 数据库中没有任何记录的表

问题描述 投票:0回答:1

我有一个 Firebird 4.0 数据库,有 724 个表,我需要搜索一些数据。首先,我想删除没有任何记录的表。 Firebird 中是否有类似于下面 MySQL 中的示例的内容?

SELECT TABLE_NAME, TABLE_ROWS
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = '<database MySQL>;

返回没有任何记录的表或有行数的表等的查询。这可以帮助我识别哪些表是空的。

我尝试使用 $rdb$relations 进行一些查询,但没有任何效果。

sql firebird firebird-4.0
1个回答
0
投票

您可以使用命令行工具

gstat
,例如
gstat -u <your user> -d -r <database>
,它将报告所有表的多项统计信息,包括行数。

否则,您将需要自己编写一个存储过程或执行块(对于大型数据库来说运行速度可能很慢),例如:

execute block returns (TABLE_NAME varchar(63) character set UTF8, TABLE_ROWS bigint)
as
begin
  for select trim(RDB$RELATION_NAME) from RDB$RELATIONS
      where RDB$SYSTEM_FLAG = 0 and RDB$RELATION_TYPE = 0
      into TABLE_NAME do
  begin
    execute statement 'select count(*) from "' || replace(TABLE_NAME, '"', '""') || '"' into TABLE_ROWS;
    suspend;
  end
end

如果您只想输出带有

TABLE_ROWS = 0
的行,则需要使
suspend
语句有条件,例如:

if (TABLE_ROWS = 0) then suspend;
© www.soinside.com 2019 - 2024. All rights reserved.