Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I was looking into a way to find in a given database if there were any table if a column that matched a specific name. After researching and talking to colleagues these two possible solution have arisen:

SQL
SELECT
	table_name
	,column_name 
FROM
	information_schema.columns
WHERE
	column_name like '%word%'

And
SQL
SELECT
	t.name AS TableName
	,c.name AS ColName
FROM 
	sys.columns c
JOIN 
	sys.tables t ON c.object_id = t.object_id
WHERE c.name LIKE '%word%'


Is there a performance difference between them? when? Any suggestions on how to improve it?

thx
Posted
Comments
Herman<T>.Instance 22-Oct-13 9:35am    
What is your exact problem?
Paulo Augusto Kunzel 22-Oct-13 9:44am    
Hi digimanus,
I want to keep the performance for the moment my database gets larger and it would be good to have the opinion of people with more experience in the area. It is a big project and there will be many tables.
Herman<T>.Instance 22-Oct-13 9:50am    
in both cases you examn mastertables so I do not see a performance issue
Paulo Augusto Kunzel 22-Oct-13 11:05am    
Fair enough,
If you believe it to be the case, post it as a solution and I'll close this question
Herman<T>.Instance 23-Oct-13 6:55am    
why don't you test it yourself

1 solution

I tested both queries in SQL Server Management Studio.
I turned on "Include Actual Execution Plan".

The first query required one join and two index seeks/scans.
The second query required three joins and four index seeks/scans.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900