I was working on deployment of a new application. Part of the deployment plan was to clean certain tables and bootstrap some configuration tables. I had some SQL scripts to accomplish these tasks. But as the number of tables started growing, we were running into issues with somebody forgetting to update these set up scripts. One of the solutions we came up was to generate a report after each deployment to get list of empty tables and list of tables that have records in it. After doing some search in SQL server's documents and on news groups, I finally found example of a SQL query that provides list of empty tables. I just created a second query that gives me list of tables that have records and count of records in those tables. This approach has worked wonders to make sure that deployment is correct.
select 'Table'=convert(char(50),t.TABLE_NAME), 'Total records in table'=max(si.rows) from sysindexes as si, INFORMATION_SCHEMA.TABLES as t where t.TABLE_NAME = object_name(si.id) and t.TABLE_TYPE = 'BASE TABLE' group by t.TABLE_SCHEMA, t.TABLE_NAME HAVING max(si.rows)<=0
select 'Table'=convert(char(50),t.TABLE_NAME), 'Total records in table'=max(si.rows) from sysindexes as si, INFORMATION_SCHEMA.TABLES as t where t.TABLE_NAME = object_name(si.id) and t.TABLE_TYPE = 'BASE TABLE' group by t.TABLE_SCHEMA, t.TABLE_NAME HAVING max(si.rows) > 0
Find empty tables in a database
The database principal owns a database role and cannot be dropped
How to plan CCSP Exam preparation
Develop a MongoDB pipeline to transform data into time buckets
Alert and Confirm pop up using BootBox in AngularJS
AngularJS Grouped Bar Chart and Line Chart using D3
How to lock and unlock account in Asp.Net Identity provider
2024 © Byteblocks, ALL Rights Reserved. Privacy Policy | Terms of Use