Question Drew Holloway · Mar 12, 2020

How to search all tables for specific column in Intersystems Cache database

Is there a way to query the database structure?  In SSMS there are queries for finding tables with a column with a certain name (using LIKE).  And there is the redgate tool SQL Search.  But I'm not sure how to go about looking for columns that have say a value of 'PATID' and returning all tables that match.  Does anyone know?

Comments

Peter Steiwer · Mar 12, 2020

Something like this may work:

SELECT parent FROM %Dictionary.CompiledProperty where name like 'Name' and NOT %ID %Startswith '%'

This will give you all tables that aren't % classes that have a "Name" property

0
Drew Holloway  Mar 13, 2020 to Peter Steiwer

It says I'm not priveleged for this operation.  But thanks for letting me know.

0
Benjamin De Boe  Mar 15, 2020 to Drew Holloway

indeed, system schemas (whose name starts with a % sign) require certain privileges (that you quickly get used to once you have them :-) ). That's why I suggested querying the INFORMATION_SCHEMA

0
Benjamin De Boe · Mar 13, 2020

and if you prefer something more database-independent, you can use the standard INFORMATION_SCHEMA package:

SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE 'PATID%'
0
Drew Holloway  Mar 13, 2020 to Benjamin De Boe

Thank you!  This worked well!

0