find column name in db

Vineet S 425 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
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,353 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,600 questions
0 comments No comments
{count} votes

Accepted answer
  1. Erland Sommarskog 107.1K Reputation points
    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 25,651 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