Searching for a database field in the SQL Server Database

  • I am new to SQL Server and working on a new Data Base. I need to search the SQL Server database and list all Table names that have a Field I am looking for.

    In Oracle I would do

    SELECT column_name, Table_name FROM all_tab_columns

    WHERE column_name = 'POS_TRANSACTION' ----Name_Of_Field from tables that I'm looking for

    This will list all tables that have the field name.

    How do I do this in SQL Server?

    Thanks, Jim

  • SQL is very similar, and there's two ways:

    select TABLE_NAME,COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where COLUMN_NAME='POS_TRANSACTION'

    --or

    select OBJECT_NAME(object_id) As TableName, name As ColumnName from sys.columns where name ='POS_TRANSACTION'

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • It works great. Thank you for the quick reply.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply