SQL Scripts: Record Counts

As I’m populating a sample set of data in a SQL Server project, I needed a quick way of identifying what tables I had missed. Here’s what I came up with (but a much faster way is noted below using the sys tables). — Identifies zero record count tablesdeclare @vtb varchar(200)declare @vsc varchar(200) declare x cursor for select table_schema,table_name from information_schema.tablesopen xfetch next from x into @vsc,@vtbdeclare @vcnt intprint ‘declare @vcnt int’while @@FETCH_STATUS = 0begin set @vcnt = 0print ‘set @vcnt = 0’print ‘select @vcnt=count(*) from ‘ + @vsc+’.[‘+@vtb + ‘]’print ‘if @vcnt=0 print ”’ + @vsc+’.’+@vtb + ”” fetch …



48 Stonemeadow Drive
Kanata, Ontario K2M2K2

+1 613-851-4496 Contact Us



Coming Soon