Home > Database > Mysql Tutorial > How Can I Find Tables Containing Columns with a Specific Name in SQL Server?

How Can I Find Tables Containing Columns with a Specific Name in SQL Server?

DDD
Release: 2025-01-20 00:36:08
Original
281 people have browsed it

How Can I Find Tables Containing Columns with a Specific Name in SQL Server?

How to find tables containing specific column names in SQL Server?

Using Transact-SQL query, you can query the table name containing the specified column name.

Lookup table:

To find tables that contain columns with names similar to '%MyName%', use the following query:

SELECT      c.name  AS 'ColumnName'
            ,(SCHEMA_NAME(t.schema_id) + '.' + t.name) AS 'TableName'
FROM        sys.columns c
JOIN        sys.tables  t   ON c.object_id = t.object_id
WHERE       c.name LIKE '%MyName%'
ORDER BY    TableName
            ,ColumnName;
Copy after login

Lookup tables and views:

To find tables and views that contain columns with names similar to '%MyName%', use the following query:

SELECT      COLUMN_NAME AS 'ColumnName'
            ,TABLE_NAME AS  'TableName'
FROM        INFORMATION_SCHEMA.COLUMNS
WHERE       COLUMN_NAME LIKE '%MyName%'
ORDER BY    TableName
            ,ColumnName;
Copy after login

The above is the detailed content of How Can I Find Tables Containing Columns with a Specific Name in SQL Server?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template