How to Find Tables That Contain a Certain Column Name in MS-SQL

You downloaded software which installed a database. You are a freelancer who has been asked to deal with a database whose schema you have never seen before. You have been working with a database but it has hundreds of tables and you are not sure where to look. But you have an idea what to look for in the name of a column. Now, of course, you can go table by table in Microsoft SQL Server Management Studio looking for it; or you can just run a query and find what you look for in a couple of minutes.

SELECT t.name AS table_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 '%attr%'
	ORDER BY t.name;

When you create a schema and later on proceed with creating tables, stored procedures and all other good things, every table name, column name, parameter name is stored in the system tables of the database you created. This gives you the power to search for metadata. In the example above you will get a list of tables that have a column containing “attr” in the name.

This entry was posted in MSSQL and tagged , , , , , . Bookmark the permalink.

4 Responses to How to Find Tables That Contain a Certain Column Name in MS-SQL

  1. Keep posting stuff like this i really like it

  2. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I assume I am not the only one having all the enjoyment here! Sustain the good work.Cincinnati Reds Hats,Philadelphia Phillies Hats,Canada Goose Coats

  3. You can certainly see your expertise within the work you write. The world hopes for even more passionate writers like you who aren’t afraid to say how they believe. All the time go after your heart.

Leave a Reply

Your email address will not be published. Required fields are marked *