Useful SQL Query Snippets: Table Sizes

I can’t count the number of times I’ve used this query at various sites. It started when I needed to use As with many things these days, I found it on StackOverflow but I want to document it here in case it ever goes missing. While it makes use of the sys. tables (which numerous articles say may change in the future ) as opposed to INFORMATION_SCHEMA, the end result compares the size of tables while using the partitions and tables for calculating sizes. We use this often for identifying which tables need to be cleared out or reduced when creating …

More…

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 …

More…

Contact

48 Stonemeadow Drive
Kanata, Ontario K2M2K2

+1 613-851-4496 Contact Us

Connect

Newsletter

Coming Soon