Finding columns in tables
In the past days, I have found a lot of people asking themselves, 'how do I know in which tables I can find xyz column name, and how do I know I have all the tables?' The answer to this question is often used to make database wide updates and perform a number of maintenance functions for master records and transactions that were not recorded as originally intended. The following example query attempts to solve the issue by exposing all tables were the account index (ACTINDX) column is found within the Fabrikam database (TWO). -- Created by Mariano Gomez, MVP -- This code is licensed under the Creative Commons -- Attribution-NonCommercial-ShareAlike 3.0 Unported License. -- http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode -- DECLARE @ColumnName VARCHAR(30); SET @ColumnName = 'ACTINDX'; SELECT DISTINCT RTRIM(OBJS.NAME) FROM SYS.COLUMNS COLS INNER JOIN SYS.OBJECTS OBJS ON (COLS.OBJECT_ID = OBJS.OBJECT_ID) INNER JOIN SYSINDEXES INDX ON (COLS.OBJECT_ID ...