Skip to content

Instantly share code, notes, and snippets.

@DocGreenRob
Last active May 22, 2024 06:38
Show Gist options
  • Save DocGreenRob/b8074db95dc0017ad80224c9740ea9c9 to your computer and use it in GitHub Desktop.
Save DocGreenRob/b8074db95dc0017ad80224c9740ea9c9 to your computer and use it in GitHub Desktop.
Find references in all Columns and Tables
SELECT column_name,
table_name,
table_schema
FROM information_schema.columns
WHERE column_name LIKE '%calendar%'
AND table_schema IN ( 'dbo' )
ORDER BY table_name, column_name
@DocGreenRob
Copy link
Author

To find all tables that have a particular column, you can use the following SQL query:

SELECT 
    TABLE_NAME, 
    COLUMN_NAME
FROM 
    INFORMATION_SCHEMA.COLUMNS
WHERE 
    COLUMN_NAME = 'YourColumnName';

Replace 'YourColumnName' with the name of the column you are looking for.

To find all stored procedures that reference a particular column, you can use this query:

SELECT 
    ROUTINE_NAME, 
    ROUTINE_TYPE, 
    ROUTINE_DEFINITION
FROM 
    INFORMATION_SCHEMA.ROUTINES
WHERE 
    ROUTINE_DEFINITION LIKE '%YourColumnName%'
    AND ROUTINE_TYPE = 'PROCEDURE';

Replace 'YourColumnName' with the name of the column you are looking for. This query searches for stored procedures that contain the column name within their definition.

Both queries should be run in SQL Server Management Studio (SSMS). Let me know if you need further customization or assistance!

@DocGreenRob
Copy link
Author

[Azure Data Factory | Copy multiple tables in Bulk with Lookup & ForEach](https://www.youtube.com/watch?v=KsO2FHQdILs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment