A
Andrew John
Dear All,
I'm trying to right a query for MS Access, that returns the number of rows in each table in the database.
This query works fine for SQL server. Is there an MS Access equivalent?
- It needs to be a query, NOT VBA code, so I can't figure out how to "get at" tabledefs, or whatever Access uses (if
anything), as the equivalent of systables/sysindexs/information_schema's
declare @sCurTable varchar(400)
declare @sCurTableType varchar(400)
set nocount on
declare crsTables cursor for
select TABLE_NAME, TABLE_TYPE from INFORMATION_SCHEMA.TABLES
where TABLE_NAME not in ( 'sysconstraints', 'syssegments')
create table #TblCounts(TblName sysname, TblType varchar(30), QtyRows bigint)
open crsTables
fetch next from crsTables into @sCurTable, @sCurTableType
while @@fetch_status = 0
begin
insert into #TblCounts (TblName, TblType, QtyRows)
exec ('select ''' + @sCurTable + ''', ''' + @sCurTableType + ''', '''' + count(*) from ' + @sCurTable)
fetch next from crsTables into @sCurTable, @sCurTableType
end
select TblName, TblType, QtyRows
from #TblCounts
order by TblType desc, TblName
close crsTables
deallocate crsTables
drop table #TblCounts
Regards
AJ
I'm trying to right a query for MS Access, that returns the number of rows in each table in the database.
This query works fine for SQL server. Is there an MS Access equivalent?
- It needs to be a query, NOT VBA code, so I can't figure out how to "get at" tabledefs, or whatever Access uses (if
anything), as the equivalent of systables/sysindexs/information_schema's
declare @sCurTable varchar(400)
declare @sCurTableType varchar(400)
set nocount on
declare crsTables cursor for
select TABLE_NAME, TABLE_TYPE from INFORMATION_SCHEMA.TABLES
where TABLE_NAME not in ( 'sysconstraints', 'syssegments')
create table #TblCounts(TblName sysname, TblType varchar(30), QtyRows bigint)
open crsTables
fetch next from crsTables into @sCurTable, @sCurTableType
while @@fetch_status = 0
begin
insert into #TblCounts (TblName, TblType, QtyRows)
exec ('select ''' + @sCurTable + ''', ''' + @sCurTableType + ''', '''' + count(*) from ' + @sCurTable)
fetch next from crsTables into @sCurTable, @sCurTableType
end
select TblName, TblType, QtyRows
from #TblCounts
order by TblType desc, TblName
close crsTables
deallocate crsTables
drop table #TblCounts
Regards
AJ