0 votes
1 view
in SQL by (20.3k points)

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

LIKE '%myName%'

?

1 Answer

0 votes
by (40.4k points)

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
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...