Quick Script: Finding Specific Columns

I like scripts.  Scripts that help me do things.

Working in the financial industry, there are always things that you have to ensure are protected.  More specifically, social security number and date of birth.

If your environment is like most, there are legacy applications that have a database behind the scenes that when developed 20 years ago didn’t take this into account.  Yes, these types of systems still exist.  I promise you that.

Anyway, I wrote this quick script to interrogate each database on the server to look for a specific column name pattern.  Keep in mind, you might need to adjust the data types.  In the script below, I was looking for social security numbers and they are usually stored as a string.  This is due to the fact that a social security number can start with a zero and SQL server will happily truncate that off if it is stored as a numeric value.

NOTE:  I’ve run this on production systems before and have zero issues.  However, your mileage may vary so run it at your own risk.  Do not run code you find on the internet on production systems without testing it first.  


© 2017, John Morehouse. All rights reserved.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.