Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)
closed by

Is it possible to query for table names which contain columns being

LIKE '%myName%'

?

closed

1 Answer

0 votes
by (40.7k points)
selected by
 
Best answer

Head over to this video to understand LIKE Operator in SQL.

Use this Query to search Tables & Views:

SELECT      COL_NAME AS 'Column_Name', TAB_NAME AS 'Table_Name'

FROM        INFORMATION_SCHEMA.COLUMNS

WHERE       COL_NAME LIKE '%MyName%'

ORDER BY    Table_Name, Column_Name;

• Schema.COLUMNS - the name of the schema of fetched column

• Table_Name - the name of the fetched table

• Here, one row represents a table

OR 

Use this Query to search the Tables:

SELECT col.name  AS 'ColumnName', tab.name AS 'TableName'

FROM sys.columns col

JOIN sys.tables  tab  ON col.object_id = tab.object_id

WHERE col.name LIKE '%MyName%'

ORDER BY TableName,ColumnName;

If you wish to learn SQL then visit this SQL Training.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jan 5, 2021 in SQL by Appu (6.1k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.4k questions

32.5k answers

500 comments

108k users

Browse Categories

...