How do I list or search all the column names in my database?
I want to search for a string in the names of the columns present in a database.I’m working on a maintenance project and some of the databases I deal with have more than 150 tables, so I'm looking for a quick way to do this. What do you recommend?
You can use the following query to list SQL server search for the column name in a database.
USE AdventureWorks GO SELECT t.name AS table_name, SCHEMA_NAME(schema_id) AS schema_name, c.name AS column_name FROM sys.tables AS t INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID WHERE c.name LIKE '%EmployeeID%' ORDER BY schema_name, table_name;
You can make use of information_schema views to list all objects in SQL Server 2005 or 2008 databases.
SELECT * FROM information_schema.tables SELECT * FROM information_schema.columns
Hope this helps you solve SQL server search for the column name efficiently!