find column name in db

Vineet S 1,390 Reputation points
2024-03-03T10:43:17.8533333+00:00

Hey,

how to find a data in the database for an example . I want to find out mobile number column from all tables in database

Azure SQL Database
Developer technologies Transact-SQL
SQL Server Other
0 comments No comments
{count} votes

Accepted answer
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2024-03-03T10:56:19.25+00:00

    I typically run queries like:

    SELECT s.name, t.name, c.name
    FROM   sys.columns c
    JOIN   sys.tables t ON c.object_id = t.object_id
    JOIN   sys.schemas s ON t.schema_id = s.schema_id
    WHERE  c.name LIKE '%mob%'
    

    Of course this assumes that the column naming is "reasonable". For a larger database with many tables, this can be a bit of needle-in-a-haystack thing.

    Note: because you can add up to five tags in a post, doesn't mean that you have to. I took the liberty to remove two tags that were entirely irrelevant.


1 additional answer

Sort by: Most helpful
  1. LiHongMSFT-4306 31,566 Reputation points
    2024-03-04T03:17:48.31+00:00

    Hi @Vineet S

    Try this:

    SELECT * 
    FROM information_schema.columns 
    WHERE column_name = '
    

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.