Skip to main content

Posts

Showing posts from May, 2018

DMV To List Foreign Keys With No Index

I was entrusted with a new database for a critical application that was having general performance issue and the CPU usage constantly over 70%. It turned out that I did not have to sweat much to quickly and significantly improve the database performance and also bring down CPU % way below the threshold. The solution? For one thing, the database was missing many much needed indexes.  After making sure that it was the right thing to do, I added the indexes that would give the biggest performance boost. It instantly and greatly improved the performance. I was the hero! Secondly, the foreign key columns were not indexed and because of their relative small size, they would not easily be captured by the the famous sys.dm_db_missing_index_details DMV. Lack of indexes in foreign keys was not only causing minutely noticeable  performance impact but also leading to lock escalations that during heavy loads cause dead locks and exacerbating the situation. So I wrote the below query to get...

How To Audit Data Changes In SQL Server?

Scenario: I was at a new client, with their previous and only DBA / DEVELOPER/ MASTER OF ALL of 8 years all suddenly gone with no documentation. Their business critical application was having data integrity issues. Some data were updated incorrectly while some others were not updated at all, showing old or incorrect data to their users/customers/vendors etc... After going through their stored procedures, triggers, view, ETLs, SQL trace etc... I was able to track down and fix most of the data issues. But there was one particular table that I could not figure out.  I thought maybe that table is never updated? How can I be sure what is going on with it? I decided I need to setup something to automatically monitor this table for few days.  Here, SQL server offers few options: Profiler trace Server side trace Extended events Audits Triggers CDC/CTC Service brokers .......... I knew that I only need to know how this particular table is being updated. I don't need to know the actual ...