Exporting Column Headers to Excel

  • Hi Guys,

    I have to complie a list of column names and their data types in excel, is there anyway to export it from SQL?

    It will take me for ever if I have to type it out.

    It's not all the tables in the DB, its just a couple.

    I would grately appreciate any help.

    Thanks

  • Found a query for this.

    To all who would need to do this in the future, use:

    Use db_Name

    SELECT column_name 'Column Name',

    data_type 'Data Type',

    CHARacter_maximum_length 'Maximum Length'

    FROM information_schema.columns

    WHERE table_name = 'table_name'

  • This may work better as you don't need to run it for any given table SELECT OBJECT_NAME(c.object_id) ,

    c.name ,

    p.name ,

    c.max_length

    FROM sys.tables t

    JOIN sys.columns c ON t.object_id = c.OBJECT_ID

    JOIN sys.types p ON c.user_type_id = p.user_type_id

    WHERE type = 'U'

    ______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience

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

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